list.append seems to break return type checker
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
Hello, concerning the function below:
from typing import List
def foo() -> List[int]:
listings = None
if 2 != 2:
listings = list()
listings.append(1)
return listings
I expected:
Incompatible return value type (got "Optional[List[int]]", expected "List[int]")
I got no error
This one does throw the expected error (same config):
from typing import List
def foo() -> List[int]:
listings = None
if 2 != 2:
listings = [1]
return listings
running mypy 0.770 on python 3.8
I would appreciate it if you could tell me if I am doing something wrong :)
Have a good day !
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 i due snippet con mypy 0.770 su Python 3.8 e confronta il tipo inferito di listings prima del return. Traccia la gestione di list.append rispetto al letterale di lista, quindi aggiungi un test di regressione che mostri che entrambi i casi producono l’errore atteso Optional[List[int]] per il valore restituito.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- tooling
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100