exit() builtin has return type NoneType, but should have return type NoReturn
wyattscarpenter opened this issue · comments
I have this function
from typing import NoReturn
def example() -> NoReturn:
exit()
pytype gives me this error:
bad return type [bad-return-type]
Expected: Never
Actually returned: None
I think this is because https://github.com/google/pytype/blob/main/pytype/stubs/builtins/builtins.pytd#L84 lists the return type of exit
as NoneType
instead of NoReturn
. This also affects quit
.
Indeed, reveal_type(exit) is Callable[[Any], None], and if instead I define a new function, example2, that raises an exception and is declared to return NoReturn, then pytype deduces correctly that there is no error when I call that from example instead of calling example from exit.
For further context see also https://github.com/google/pytype/blob/main/pytype/stubs/builtins/typing.pytd#L412 where the NoReturn is set to nothing
, not NoneType
or None
.
You can also see that in typeshed, they've decided the type of exit (and also quit) should be (code: sys._ExitCode = None) -> NoReturn
https://github.com/python/typeshed/blob/main/stdlib/builtins.pyi#L1336