valid-type not reported for variables imported in other modules
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 20.6k
- Fork
- 3.3k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
Bug Report
Mypy reports [valid-type] for a variable defined in the same file but not when the variable is imported in other files.
To Reproduce
Create 3 files
# app/example_a.py
def dynamic_type(x):
return type("some_type", () , x)
# app/example_b.py
from app.example_a import dynamic_type
SOME_FAKE_TYPE = dynamic_type({"a": "a"})
x: SOME_FAKE_TYPE
# app/example_c.py
from app.example_b import SOME_FAKE_TYPE
x: SOME_FAKE_TYPE
Expected Behavior
Mypy should raise [valid-type] errors in both app/example_b.py and app/example_c.py
Actual Behavior
It only reports [valid-type] errors in app/example_b.py
app/example_b.py:6: error: Variable "app.example_b.SOME_FAKE_TYPE" is not valid as a type [valid-type]
app/example_b.py:6: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
Your Environment
$ uv run mypy --version
mypy 1.16.0 (compiled: yes
- Mypy version used: 1.16.0
- Mypy command-line flags:
mypy - Mypy configuration options from
mypy.ini(and other config files):
[mypy]
check_untyped_defs = True
follow_imports = normal
disallow_untyped_defs = False
files = app/
- Python version used: 3.11.8
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia riproducendo il report con app/example_a.py, app/example_b.py e app/example_c.py usando mypy 1.16.0, quindi confronta le diagnostiche [valid-type] per le variabili locali e importate. La correzione è completa quando mypy segnala l’errore previsto sia in example_b.py sia in example_c.py senza modificare l’intento della riproduzione.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- compilers
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 45/100