8000 Should `object.__eq__` return `object`? · Issue #7150 · python/typeshed · GitHub
[go: up one dir, main page]

Skip to content

Should object.__eq__ return object? #7150

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

Closed
kmillikin opened this issue Feb 7, 2022 · 1 comment
Closed

Should object.__eq__ return object? #7150

kmillikin opened this issue Feb 7, 2022 · 1 comment

Comments

@kmillikin
Copy link

In builtins.pyi there is:

def __eq__(self, __o: object) -> bool: ...
def __ne__(self, __o: object) -> bool: ...

But I think that both of these methods should return object. I believe that they eventually get called in CPython by tp_richcompare which doesn't necessarily return bool (https://github.com/python/cpython/blob/1626bf4ac7aef1244e6f886e63a31f7ed65fbd10/Objects/object.c#L655).

There is Python code that takes advantage of this to override == to return something other than a bool (e.g., numpy arrays). Type checking code like that against the typeshed type stubs leads to incompatible overrides (e.g., numpy array is not a subtype of bool).

Should these methods be annotated as returning object?

@srittau
Copy link
Collaborator
srittau commented Feb 8, 2022

See #3685.

@srittau srittau closed this as completed Feb 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
0