Hey,
I noticed that writing a class with a classmethod `__eq__`, it does not work as
expected:
```python
class ANY:
@classmethod
def __eq__(cls, other):
return True
assert ANY == 2 # succeeds
assert ANY == 2 # fails
```
This is, to my understanding, because `ANY == 2` translates into
`type(ANY).__eq__(2)`.
However, I think it would be useful to allow user implementation of
`classmethod` dunder methods that work as expected, or at least put a big
disclaimer in the documentation. I am not sure how difficult this would be to
do, but I imagine that `type` could check if the given object/class has a
classmethod __eq__ and if so use it as a replacement for `type(obj).__eq__`
As a sidenote, I think it would actually be kinda cool to have the `typing.Any`
behave this way, i.e. always comparing to True.
One example where this would be useful is that it would allow comparisons like
```python
assert mytuple == (Any, "abc")
```
which would then be equivalent, but imo a lot more elegant than
```python
assert len(mytuple) == 2 and mytuple[-1] == "abc"
```
Best regards - Randolf
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/L5X2PTDTV3Q5VBJKLBECHRHENVPNHJTU/
Code of Conduct: http://python.org/psf/codeofconduct/