typing icon indicating copy to clipboard operation
typing copied to clipboard

Handle special object NotImplemented like type (like it done for None)

Open penguinolog opened this issue 5 years ago • 3 comments

Currently incorrect, but useful to be supported:

def fun() -> Union[bool, NotImplemented]: ...

This will better explain expected, than:

def fun() -> Union[bool, Any]: ...

penguinolog avatar Jul 22 '20 07:07 penguinolog

What’s a realistic use case?

gvanrossum avatar Jul 22 '20 13:07 gvanrossum

Real use-cases: mainly reversible operations, where NotImplemented cause reverse operation (__add__ -> __radd__ and etc)

penguinolog avatar Jul 22 '20 14:07 penguinolog

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>

gvanrossum avatar Jul 22 '20 15:07 gvanrossum