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
Include documentation on how this works #38
Comments
My guess would be that the docs are slightly out of date and in reality either:
Honestly I haven't looked into it in more detail, but I would guess it's more than just an implementation detail since it also works with pypy. |
If you feel like digging into the source and working out what's going on, I'd love to see a write up and we could add it to the docs. From a brief experiment my suggestion seems to be correct: class A:
pass
class B:
def __eq__(self, other):
print('used B.__eq__')
return True
class C:
def __eq__(self, other):
print('used C.__eq__')
return True
assert A() == B() # used B.__eq__
assert B() == A() # used B.__eq__
assert B() == C() # used B.__eq__
assert C() == B() # used C.__eq__ In summary: if one instance has a custom |
I haven't found any documentation on how NotImplemented is handled, but it seems to cause Python to try the I still haven't figured out in which situations I'm not sure if I can find the time to write something up, but I'll try to find the time this week for a paragraph or two. |
I find this functionality quite interesting and think it could be useful.
But I'm a bit hesitant to include a library with "magical" behavior that I don't understand.
My main question is, why is the
__eq__
method of the right operand used?The python documentation seems to suggest that
x == y
should callx.__eq__(y)
.The last paragraph in the docs above point me to the
__eq__
implementation in theDirtyEqualsMeta
class. But I'm not sure what is going on.The text was updated successfully, but these errors were encountered: