false positive "name not defined" with list comprehension in function arguments default value
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 20.6k
- Fork
- 3.3k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
- 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
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Riproduci il problema eseguendo mypy repro.py con le varianti dell’ordine delle funzioni indicate sulla versione di git-master a cui si fa riferimento. Traccia la gestione dei valori predefiniti degli argomenti delle funzioni e degli scope delle list comprehension, quindi aggiungi un test di regressione che copra entrambi gli ordini; il lavoro è completato quando non si verificano errori di nome falsi positivi e la suite esistente ha esito positivo.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- devtools
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100