Skip to content

mypy does not recognize os.name #13002

@amatyukhin0

Description

@amatyukhin0

Bug Report

mypy respects platform conditions using sys.platform variable, but do not recognize os.name.

Related issue: #8166

To Reproduce

Consider this piece of code, assuming we are on Linux:

import os
import signal

if os.name == 'nt':
    signal_type = signal.SIGBREAK
else:
    signal_type = signal.SIGTERM

Expected Behavior

mypy should not raise any error.

Actual Behavior

mypy fails with:

main.py:5: error: Module has no attribute "SIGBREAK"
Found 1 error in 1 file (checked 1 source file)

Note that replacing os.name == 'nt' with sys.platform == 'win32' fixes this issue.

Environment

  • Mypy version used: 0.961
  • Python version used: 3.10
  • Operating system: Linux

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions