Skip to content

Respect sys.platform platform check assertion inside functions #9025

Open
@nipunn1313

Description

@nipunn1313

This is a feature request

From the docs
https://mypy.readthedocs.io/en/stable/common_issues.html#python-version-and-system-platform-checks

More specifically, mypy will understand the use of sys.version_info and sys.platform checks
within if/elif/else statements.

and

As a special case, you can also use one of these checks in a top-level (unindented) assert; this makes mypy skip the rest of the file.

It would be nice if this kind of code would also typecheck on mac/linux.
Currently the option is to refactor such that you can define the entire function within an if sys.platform == "win32"

class A:
   def func_on_win_only() -> str:
      assert sys.platform == "win32"
      return sys.getwindowsversion()

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions