python / python/mypy

(🐞) platform specified in inline configuration results in wacky behavior

Open
#12,926 0 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug topic-configuration
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

It seems like even though this is not a per module option, it is still being applied to the module, but it's using the global(linux) type defs.

import sys, winreg

if sys.platform == "win32":
    winreg.QueryValueEx

# Success: no issues found in 1 source file
# mypy: platform=win32
import sys, winreg

if sys.platform == "win32":
    winreg.QueryValueEx  # test.py:5:5: error: Module has no attribute "QueryValueEx"  [attr-defined]

playground

  • Relates to: #12342

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 provided mypy-play reproduction and compare how the inline # mypy: platform=win32 setting is processed with the equivalent global platform setting. Check why the module uses Linux type definitions despite the inline option; done means the guarded winreg.QueryValueEx reference is accepted with the inline setting, with a regression test covering the example.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.