python / python/mypy

mypy does not recognize os.name

Open
#13,002 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature priority-2-low
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.