I have the following (typed) Python function:
from typing import overload, Literal, NoReturn
@overload
def check(condition: Literal[False], msg: str) -> NoReturn:
pass
@overload
def check(condition: Literal[True], msg: str) -> None:
pass
def check(condition, msg):
if not condition:
raise Exception(msg)
Pyright type-checker complains:
Overloaded function implementation is not consistent with signature of overload 1
Function return type "NoReturn" is incompatible with type "None"
Type cannot be assigned to type "None"
I'm confused by this-- Pyright apparently can't determine that check will always throw an error if condition is False. How can I massage this to make it work?