python / python/mypy

enigmatic "name already defined" error

Offen
#7,206 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

bug priority-1-normal
Vorherrschende Sprache
Python
Sterne
20.6k
Forks
3.3k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

Please provide more information to help us understand the issue:

  • Are you reporting a bug, or opening a feature request?

Bug.

  • Please insert below the code you are checking with mypy,
    or a mock-up repro if the source is private. We would appreciate
    if you try to simplify your case to a minimal repro.

There are four pieces of code:

def func(x: int) -> int:
    return x + 1

def func(x):
    return x
def func(x):
    return x

def func(x: int) -> int:
    return x + 1
from test import func

def func(x: int) -> int:
    return x + 1
def func(x: int) -> int:
    return x + 1

from test import func

Whenever test is used as a module, test.py contains

def func(x):
    return x
  • What is the actual behavior/output?

The first three examples emits "Name 'func' already defined" error, but not the last

  • What is the behavior/output you expect?

All four should emit this error.

  • What are the versions of mypy and Python you are using?

mypy 0.720+dev.dc6da54f50d5443fe46308046719043eba03c84d (master at the time of bug report)
Python 3.7.3

  • What are the mypy flags you are using? (For example --strict-optional)

None.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne damit, die vier Inline-Reproduktionen mit der gemeldeten mypy-Version auszuführen, wobei du test.py für die importierte Funktion verwendest. Vergleiche die Diagnosen für jede Reihenfolge von Import und Neudefinition. Erledigt ist dies, wenn das Verhalten der Erwartung des Reports entspricht, dass alle vier Fälle den duplicate-definition-Fehler ausgeben.

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
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.