On 7/26/20 10:31 AM, Henry Lin wrote:
You're right, declaring `__eq__` for the class we want to compare would
solve this issue. However, we have the tradeoff that
* All classes need to implement the `__eq__` method to compare two
instances;
I usually implement __eq__ sooner or later anyway -- even if just for
testing.
* Any class implementing the `__eq__` operator is no longer hashable
One just needs to define a __hash__ method that behaves properly.
* Developers might not want to leak the `__eq__` function to other
developers; I wouldn't want to invade the implementation of my class
just for testing.
And yet that's exactly what you are proposing with your object compare.
If two objects are, in fact, equal, why is it bad for == to say so?
--
~Ethan~
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/python-ideas@python.org/message/XFX6SXJ3QULMW3N5GZFA7CGDVXWF3KQM/
Code of Conduct: http://python.org/psf/codeofconduct/