Skip to content

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

@dzherb

Description

@dzherb

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions