As suggested by Ryan in D1019, it's cleaner if we use defined constants
instead of osname == 'nt' everywhere.
Details
- Reviewers
spectral - Group Reviewers
hg-reviewers - Commits
- rHGc0a6c19690ff: pycompat: define operating system constants
Diff Detail
- Repository
- rHG Mercurial
- Lint
Lint Skipped - Unit
Unit Tests Skipped
Event Timeline
mercurial/pycompat.py | ||
---|---|---|
23 | Since osname might be different (encoding or whatever) depending on python version, I think moving these after the 'if ispy3/else' block below and using something like: isdarwin = sysplatform == 'darwin' would be better. |
mercurial/pycompat.py | ||
---|---|---|
23 | For encoding, Python 2 and 3 are compatible if we use r prefixed strings. The if condition is to normalize strings to bytes for Mercurial use. In other words, I think only types that need to be "normalized" should be put under the if condition. These is* constants have a type of bool, which does not need to be normalized. I think it's better to avoid code duplication. |
[Accepted with a very mild concern; I'm fine with it not being addressed]
mercurial/pycompat.py | ||
---|---|---|
23 | Ah, sorry, I didn't mean put it in the if blocks (duplicating it), I meant just put it at the end of the file once <thismodule>.osname and <thismodule>.sysplatform have been created in a python-version-aware fashion, not indented at all. (basically, move these three lines to the end of the file). Mostly this is paranoia and a tiny extra layer of abstraction/indirection. I don't expect it to happen, but if sys.platform renames itself in some hypothetical future python 4.2, I expect we'll continue to have a pycompat.sysplatform, and then we shouldn't need to change these lines at all, if they're using that version-agnostic sysplatform. I don't feel strongly about this though, and don't want to block you on this issue. I leave it up to you and the 2nd pass reviewers :) |
mercurial/pycompat.py | ||
---|---|---|
23 | That makes sense. I will update the patch and the previous Jython one. Thanks! |
Since osname might be different (encoding or whatever) depending on python version, I think moving these after the 'if ispy3/else' block below and using something like:
isdarwin = sysplatform == 'darwin'
isposix = osname == 'posix'
iswindows = osname == 'nt'
would be better.