'Name already defined' error when importing function from module with the same name
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
mypy shows an unexpected error, when I import all attributes from a module using * and a function has the same name as the module.
Example:
I have a package named foo, that contains the files __init__.pyi, a.pyi, b.pyi and c.pyi.
# a.pyi
def a() -> None: ...
# b.pyi
def not_b() -> None: ...
# c.pyi
def c() -> None: ...
# __init__.pyi
from .a import *
from .b import *
from .c import c
mypy foo shows the following error:
foo/__init__.pyi:1: error: Name 'a' already defined (by an import).
I have used mypy 0.620.
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 with the reported foo package and its init.pyi, a.pyi, b.pyi, and c.pyi files, then run mypy foo to reproduce the duplicate-name error. Trace handling of star imports and the explicit from .c import c import, and add coverage showing that the valid imports produce no erroneous redefinition diagnostic.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100