Skip to content

How can I make this # type: ignore platform specific? #8547

@evandrocoan

Description

@evandrocoan

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.py
286: def call(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 windows
289:     if isWin:
290:         si = subprocess.STARTUPINFO()
291:         try:
292:             si.dwFlags |= subprocess.STARTF_USESHOWWINDOW
  1. 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
  2. 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:

File: F:/Python/lib/subprocess.py
164: if _mswindows:
165:     class STARTUPINFO:

How can I make this # type: ignore platform specific?

(pyenv) F:\anki>mypy --version
mypy 0.761

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions