-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Labels
Description
NoReturn being a bottom type leads to mypy accepting code that I would consider to be invalid.
For example, saving the result of a NoReturn function to a variable:
import sys
from typing import List
from mypy_extensions import NoReturn
def never_returns() -> NoReturn:
sys.exit(1)
def foo() -> None:
x = [] # type: List[int]
x = never_returns()If mypy infers a type of NoReturn on my function body, it seems that I can write anything as the return type without getting a type error:
def foo1() -> dict:
raise Exception('oh dear')
def foo2() -> list:
sys.exit(1)I'm struggling to think of any example where NoReturn being a bottom type allows me to do things that I couldn't otherwise do.
What's the rationale? Would you be open to changing this?
Originally discussed in #4066.