`name.py` used as module instead of `name` module directory
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
I have a module named mdl with the below __init__.py (The contents don't actually matter).
from .document import load_document
Then I have a file called mdl.py:
import mdl
doc = mdl.load_document( "happy" )
mypy produces the error:
mdl.py:2: error: Module has no attribute "load_document"
If I rename the file to anything_else.py this error doesn't happen.
It appears as though mypy is resolving the mdl import to the file mdl.py instead of the mdl module directory. Since the Python interpreter resolve the names as I intended, I'd assume mypy would as well.
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 case with the mdl package's init.py and the sibling mdl.py file, then inspect how mypy resolves the import in mdl.py. Compare that result with Python's resolution behavior and identify the relevant import-resolution tests or entry point. Done means mypy recognizes load_document from the package directory without requiring the file to be renamed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100