Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
penguinolog opened this issue Jul 22, 2020 · 3 comments
Open

Comments

@penguinolog
Copy link

@penguinolog penguinolog commented Jul 22, 2020

Currently incorrect, but useful to be supported:

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

This will better explain expected, than:

def fun() -> Union[bool, Any]: ...
@penguinolog penguinolog changed the title Threaten special NotImplemented object like type (like it done for None) Handle special object NotImplemented like type (like it done for None) Jul 22, 2020
@gvanrossum
Copy link
Member

@gvanrossum gvanrossum commented Jul 22, 2020

What’s a realistic use case?

@penguinolog
Copy link
Author

@penguinolog penguinolog commented Jul 22, 2020

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

@gvanrossum
Copy link
Member

@gvanrossum gvanrossum commented Jul 22, 2020

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.