Always complain if returning a value if annotated to return None

Aperta
#1,509 3 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
python

Direzione di ricerca

Start by reproducing the issue's two-function example and trace how mypy analyzes a return statement in a function annotated to return None when the returned expression has type Any. Done means mypy reports this return as an error while preserving the intended handling of valid None returns.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

priority-1-normal topic-strict-optional

Mypy doesn't complain about this code that returns a value in a function declared to return None, since the return value is Any:

def f() -> None:
    return g()   # oops, but no error

def g():
    return 1

I think that mypy could complain about the return statement even if the value has type Any. The current behavior is not inconsistent or incorrect, but probably not optimal.

Lingua principale
Python
Stelle
20.6k
Fork
3.3k
Merge medio
1g 18h
PR unite (30g)
54

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di python/mypy

Tutte le issue di python/mypy

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.