You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
How can I make this # type: ignore platform specific? #8547
The project I use, runs both on Windows and Linux. The code is all platform specific, but mypy keeps ignoring it:
File: anki/pylib/anki/utils.py286: defcall(argv: List[str], wait: bool=True, **kwargs) ->int:
287: "Execute a command. If WAIT, return exit code."288: # ensure we don't open a separate window for forking process on windows289: ifisWin:
290: si=subprocess.STARTUPINFO()
291: try:
292: si.dwFlags|=subprocess.STARTF_USESHOWWINDOW
If I add # type: ignore to lines 290 and 292 then, mypy works on Linux, but it fails on Windows with error: unused 'type: ignore' comment
If I remove the # type: ignore from the lines 290 and 292 then, mypy works on Windows, but it fails on Linux with error: Module has no attribute "STARTUPINFO" [attr-defined].
The STARTUPINFO is not defined for Linux Implementations, but is is for Windows implementation. That is why both of them are both protected by a if isWin or if _mswindows on this project and on the subprocess module implementation:
Activity
JelleZijlstra commentedon Mar 19, 2020
If you use a mypy-recognized platform check like
if sys.platform == 'win32', mypy should behave as expected.evandrocoan commentedon Mar 19, 2020
The
isWinAnki uses on the if is this:The only way to
mypyto work is replacing theif isWinbyif sys.platform == 'win32'? This should be improved.JukkaL commentedon Mar 20, 2020
Mypy supports what specified in PEP 484 (https://www.python.org/dev/peps/pep-0484/#version-and-platform-checking). We could perhaps extend this to cover more cases, but it's hard to decide where we should draw the line, since the platform checks could be arbitrarily creative.
ErikBjare commentedon Jul 25, 2020
@JukkaL I'm having problems with a simple case like:
There are some valid cases where you might want to do this, especially for Windows where
sys.platformcan be one of["win32", "cygwin"].Edit: I tried with this and it worked:
JelleZijlstra commentedon Jul 26, 2020
There is an open PR #8461 to add support for
platform.system(), but it looks like it has stalled.hauntsaninja commentedon Aug 7, 2020
Closing this as a dupe of other issues, basically this entire comment #9242 (comment) applies to this issue
Use sys.platform rather than the platform module