Inconsistent module import behavior when `follow_imports=skip` and __init__ files are omitted from check list
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
Inconsistent module import behavior when follow_imports=skip and files are passed explicitly on the command line
To Reproduce
mypy.ini
[mypy]
follow_imports = skip
a.py
import mod.b
reveal_type(mod.b.UserId)
from mod.b import UserId
reveal_type(UserId)
import sib
reveal_type(sib.Sib)
from sib import Sib
reveal_type(Sib)
sib.py
class Sib:
pass
mod/b.py
class UserId:
pass
and a blank mod/__init__.py
nipunn-mbp:mypy_repro nipunn$ mypy a.py sib.py mod/b.py
a.py:2: note: Revealed type is 'Any'
a.py:4: note: Revealed type is 'def () -> mod.b.UserId'
a.py:7: note: Revealed type is 'def () -> sib.Sib'
a.py:9: note: Revealed type is 'def () -> sib.Sib'
nipunn-mbp:mypy_repro nipunn$ tree .
.
├── a.py
├── mod
│ ├── __init__.py
│ └── b.py
├── mypy.ini
└── sib.py
1 directory, 5 files
notably, you get the expected behavior when __init__.py is passed explicitly
nipunn-mbp:mypy_repro nipunn$ mypy .
a.py:2: note: Revealed type is 'def () -> mod.b.UserId'
a.py:4: note: Revealed type is 'def () -> mod.b.UserId'
a.py:7: note: Revealed type is 'def () -> sib.Sib'
a.py:9: note: Revealed type is 'def () -> sib.Sib'
nipunn-mbp:mypy_repro nipunn$ mypy a.py sib.py mod/b.py mod/__init__.py
a.py:2: note: Revealed type is 'def () -> mod.b.UserId'
a.py:4: note: Revealed type is 'def () -> mod.b.UserId'
a.py:7: note: Revealed type is 'def () -> sib.Sib'
a.py:9: note: Revealed type is 'def () -> sib.Sib'
Expected Behavior
It appears inconsistent that mypy would believe in mod.b.UserId while not believing in mod.b under these circumstances - giving different behavior for UserId depending on how it is imported. Even with follow_imports=skip - I would expect __init__.py files to be followed when a file within is explicitly declared.
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 eseguendo la riproduzione con mypy.ini, a.py, sib.py, mod/b.py e mod/init.py, quindi confronta gli elenchi espliciti dei file mostrati nel report. Traccia come vengono gestiti i moduli controllati esplicitamente e i file init.py dei package con follow_imports=skip. Il lavoro è completato quando i tipi rivelati sono coerenti indipendentemente dal fatto che mod/init.py sia elencato esplicitamente o meno.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- devtools
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 45/100