mypy does not recognize os.name
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the main.py reproducer and compare its os.name condition with mypy's existing sys.platform handling; related issue #8166 may provide context. The work is done when the Linux example type-checks without a SIGBREAK error while preserving the expected platform-specific behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100