mypy confuses module with contents at import time
Open
Nobody has claimed this yet.
bug
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Here's a minimal repro:
.
└── example
├── __init__.py
├── cell.py
└── component.py
1 directory, 3 files
λ cat example/__init__.py
from example.cell import cell
import example.component
λ cat example/cell.py
def cell() -> str:
return "asdf"
λ cat example/component.py
import example
x: str = example.cell()
And this gives you:
λ mypy example
example/component.py:3: error: Module not callable
Found 1 error in 1 file (checked 3 source files)
Despite the fact that things work at runtime:
λ python -c 'import example; print(example.component.x)'
asdf
cc @joamatab
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
Reproduce the report using example/init.py, example/cell.py, and example/component.py, then run mypy example and the shown Python runtime command. Trace how the import of example.cell is represented when example.component.py calls example.cell(); done means mypy accepts the valid call without introducing errors for the three-file example.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100