Skip to content

Recognize platform.system() as well as sys.platform #8166

Open
@brettcannon

Description

@brettcannon

Note: if you are reporting a wrong signature of a function or a class in
the standard library, then the typeshed tracker is better suited
for this report: https://github.com/python/typeshed/issues

Please provide more information to help us understand the issue:

  • Are you reporting a bug, or opening a feature request? feature request
  • Please insert below the code you are checking with mypy,
    or a mock-up repro if the source is private. We would appreciate
    if you try to simplify your case to a minimal repro.
    if platform.system() != "Windows":  # sys.platform != "win32":
        try:
            # os.confstr("CS_GNU_LIBC_VERSION") returns a string like "glibc 2.17".
            version_string = os.confstr("CS_GNU_LIBC_VERSION")
            assert version_string is not None
            _, version = version_string.split()
        except (AssertionError, OSError, ValueError):
            # os.confstr() or CS_GNU_LIBC_VERSION not available (or a bad value)...
            return None
        return version
    return None
  • What is the actual behavior/output? "error: Module has no attribute "confstr""
  • What is the behavior/output you expect? No error when run under Windows
  • What are the versions of mypy and Python you are using? mypy 0.750, Python 3.7.4

Basically it would be nice to get to use platform.system() instead of having to use sys.platform to make mypy happy with code that is conditional on the platform.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions