Skip to content

platform.system is not treated the same way as sys.platform #19039

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dzherb opened this issue May 5, 2025 · 1 comment
Closed

platform.system is not treated the same way as sys.platform #19039

dzherb opened this issue May 5, 2025 · 1 comment
Labels

Comments

@dzherb
Copy link

dzherb commented May 5, 2025

Bug Report

It seems that conditions using platform.system() are not treated the same way as those using sys.platform. I'm not sure if this is a bug or a missing feature.

To Reproduce

import platform
import sys


def works() -> None:
    if sys.platform == "win32":
        import some_win_dependency
        some_win_dependency.do_stuff()
        return
    ...
    return

def doesnt_work() -> None:
    if platform.system() == "Windows":
        import some_win_dependency  # got [import-not-found]
        some_win_dependency.do_stuff()
        return
    ...
    return

Your Environment

  • Mypy version used: 1.15.0
  • Mypy command-line flags:
  • Mypy configuration options from mypy.ini (and other config files):
  • Python version used: 3.13
@dzherb dzherb added the bug mypy got something wrong label May 5, 2025
@JelleZijlstra JelleZijlstra added feature and removed bug mypy got something wrong labels May 5, 2025
@erictraut
Copy link

erictraut commented May 5, 2025

The typing spec mandates that type checkers understand an expression of the form sys.platform == "win32". It doesn't mention the form platform.system() == "Windows". It also cautions against using more complex forms (such as call expressions) and expecting them to work with static type checkers. See this section of the typing spec for details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants