assigning a NoReturn function call
Should the following be a type error? ``` def f() -> NoReturn while True: ... x = f() ``` Neither pytype nor mypy currently catch it. martin
Hi Martin, Seems like it might be worth a linter error, but doesn't look like a type error to me. Best, Mark Mendoza
I think of it as a consistency issue - if we allow NoReturn as a type annotation, we should treat it as a type, and then `x: Any = NoReturn` should throw an error similar to `x: str = 42`. martin On Fri, Jul 31, 2020 at 4:14 PM Mark Mendoza <mendoza.mark.a@gmail.com> wrote:
Hi Martin, Seems like it might be worth a linter error, but doesn't look like a type error to me. Best, Mark Mendoza _______________________________________________ Typing-sig mailing list -- typing-sig@python.org To unsubscribe send an email to typing-sig-leave@python.org https://mail.python.org/mailman3/lists/typing-sig.python.org/ Member address: mdemello@google.com
It's fine to treat it as a type, but usually diverging (i.e. NoReturn) is the bottom type (i.e. a subtype of all other types), since assigning it always preserves soundness. e.g. ``` def f() -> NoReturn: while True: ... x: int = f() # Valid y: NoReturn = f() # Valid y: NoReturn = int # Invalid ```
participants (2)
-
Mark Mendoza
-
Martin DeMello