Inconsistent module import behavior when `follow_imports=skip` and __init__ files are omitted from check list
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
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.
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 by running the reproduction with mypy.ini, a.py, sib.py, mod/b.py, and mod/init.py, then compare the explicit file lists shown in the report. Trace how explicitly checked modules and package init.py files are handled with follow_imports=skip. Done means the revealed types are consistent whether mod/init.py is listed explicitly or not.
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
- 45/100