Should `Union[X, NoReturn]` be allowed?
PEP 484 says "Static type checkers will ensure that functions annotated as returning NoReturn truly never return, either implicitly or explicitly" But, currently, I can do this: def f(num: int | float) -> int | NoReturn: if isinstance(num, float): sys.exit() return num Even though the return type of this function is always `int`. Using `int | NoReturn` somewhat makes sense if you have overrides like this: @override def f(num: int) -> int @override def f(num: float) -> NoReturn But I don't think it still makes sense logically, as in "this function returns NoReturn, Sometimes" feels wrong. My question: Should `NoReturn` be allowed inside unions? OR should the type checker not allow that.
participants (1)
-
Tushar Sadhwani