'Name already defined' error when importing function from module with the same name
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
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.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit dem gemeldeten foo-Paket und dessen Dateien init.pyi, a.pyi, b.pyi und c.pyi und führe dann mypy foo aus, um den Fehler wegen des doppelten Namens zu reproduzieren. Verfolge die Behandlung von Sternimporten und des expliziten from .c import c-Imports und füge Abdeckung hinzu, die zeigt, dass die gültigen Importe keine fehlerhafte Diagnose zur Neudefinition erzeugen.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- devtools
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 38/100