false positive "name not defined" with list comprehension in function arguments default value
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
- Are you reporting a bug, or opening a feature request?
This is a bug I believe
- Please insert below the code you are checking with mypy
def a():
pass
def b(
bb=[list_comprehension_argument for list_comprehension_argument in "abc"
if list_comprehension_argument]
):
pass
- What is the actual behavior/output?
mypy repro.py
repro.py:5: error: Name 'list_comprehension_argument' is not defined
repro.py:6: error: Name 'list_comprehension_argument' is not defined
Found 2 errors in 1 file (checked 1 source file)
- What is the behavior/output you expect?
I believe there should be no error reported.
- What are the versions of mypy and Python you are using?
Do you see the same issue after installing mypy from Git master?
this is on mypy from git master, mypy 0.790+dev.2b704df25ca299e6936927be8d41d2ab945cee2a
- What are the mypy flags you are using? (For example --strict-optional)
This is using the default flags.
This only seem to happens if there's another function like this one, before the function with list comprehension in arguments:
def a():
pass
When removing this other function or putting it after the one with list comprehension in argument, this false positive is not reported, I mean no error are reported for:
def b(
bb=[list_comprehension_argument for list_comprehension_argument in "abc"
if list_comprehension_argument]
):
pass
def a():
pass
or
def b(
bb=[list_comprehension_argument for list_comprehension_argument in "abc"
if list_comprehension_argument]
):
pass
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
Reproduziere den Bericht, indem du mypy repro.py mit den gezeigten Varianten der Funktionsreihenfolge auf der referenzierten git-master-Version ausführst. Verfolge die Verarbeitung von Standardwerten für Funktionsargumente und Bereichen von List Comprehensions und füge anschließend einen Regressionstest hinzu, der beide Reihenfolgen abdeckt; abgeschlossen ist die Aufgabe, wenn keine falsch-positiven Namensfehler auftreten und die bestehende Testsuite erfolgreich ist.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- devtools
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100