typing
typing copied to clipboard
Handle special object NotImplemented like type (like it done for None)
Currently incorrect, but useful to be supported:
def fun() -> Union[bool, NotImplemented]: ...
This will better explain expected, than:
def fun() -> Union[bool, Any]: ...
What’s a realistic use case?
Real use-cases: mainly reversible operations, where NotImplemented cause reverse operation (__add__ -> __radd__ and etc)
Okay, this makes sense (maybe I would have understood if you had provided an example where this actually makes sense, like
class Num:
def __add__(self, other: Any) -> Union[Num, NotImplemented]:
if not isinstance(other, Num):
return NotImplemented
<add two Nums>