windows: use sys.platform == "win32" instead of is_windows#35640
windows: use sys.platform == "win32" instead of is_windows#35640
sys.platform == "win32" instead of is_windows#35640Conversation
8fa6d6f to
03b6fc6
Compare
03b6fc6 to
20b3b49
Compare
|
I wanted the check to be abstracted into a method in case multiple things would be "equivalently-Windows" from a Spack point of view. No such case exists yet (although the thread you linked is an example of treating "cygwin" and "win32" the same), but that could be handled later. However, when it comes to that, we run into the problem again. I don't think it's a major problem here but I'm generally concerned about Side note: my concern in #34779 (comment) does not apply to this PR. |
|
There is apparently no way to get One issue in the current code is that IMO this means we need to standardize on the I'd say let's switch to using this, then think about whether more stuff can be consolidated in a checker-friendly way in #34779. |
|
@tgamblin would |
|
@johnwparent: unfortunately no, there's no way to make I also find that So, really, I think we have to do it this way unless |
|
@scheibelp @johnwparent any additional thoughts? |
|
From what you're saying about |
|
I think it's really just the stuff in PEP 484 above, with no smart data flow analysis to track the value of the expression. I suspect it's bc |
967ed95 to
ae0b409
Compare
`mypy` only understands `sys.platform == "win32"`, not indirect assignments of that value to things like `is_windows`. If we don't use the accepted platform checks, `mypy` registers many Windows-only symbols as not present on Linux, when it should skip the checks for platform-specific code.
ae0b409 to
64e251a
Compare
scheibelp
left a comment
There was a problem hiding this comment.
In all cases except two I see a direct replacement
In one case an extra is-windows check is added which is unnecessary (but does not hurt either)
| ) | ||
| except FileNotFoundError as e: | ||
| if e.winerror == 2: | ||
| if sys.platform == "win32" and e.winerror == 2: |
There was a problem hiding this comment.
Note this extra check is unnecessary because this object cannot be instantiated on non-windows systems
There was a problem hiding this comment.
It’s another unfortunate mypy thing. The winerror attribute doesn’t exist on non-windows systems but mypy sees it statically, so without this you get an error at typecheck time.
…#35640) `mypy` only understands `sys.platform == "win32"`, not indirect assignments of that value to things like `is_windows`. If we don't use the accepted platform checks, `mypy` registers many Windows-only symbols as not present on Linux, when it should skip the checks for platform-specific code.
mypyonly understandssys.platform == "win32", not indirect assignments of that value to things likeis_windows. See python/mypy#9242 (comment).If we don't use the accepted platform checks,
mypyregisters many Windows-only symbols as not present on Linux, when it should skip the checks for platform-specific code.I'd like to get us to where we can enable
check_untyped_defsinmypy(see #35639), so I've pulled this off of #35639 and made it a first PR. I realize this may look uglier to some people, but I don't see a good way around it as long asmypyis going to be dumb.