CKTIS / Python
typing.Never
Il tipo vuoto non possiede alcun valore possibile.
Versione: Python 3.14; repository image, production runtime not attested
Sintassi
def stop(reason: str) -> Never: ...Il tipo vuoto non possiede alcun valore possibile.
Come annotazione di ritorno segnala al verificatore che il controllo non torna normalmente, ad esempio per un’eccezione.
L’interprete permette comunque alla funzione annotata male di restituire 7.
Esempi
from typing import Never
def stop(reason: str) -> Never:
raise ValueError(reason)
def mistake() -> Never:
return 7
try:
stop("empty")
except ValueError as error:
print(str(error))
print(mistake())
Risultato
empty 7
L’interprete permette comunque alla funzione annotata male di restituire 7.