On Tue, 19 Feb 2019 at 03:31, Rémi Lapeyre <remi.lapeyre at henki.fr> wrote: > Nick Coghlan proposes to make __int__ defaults to __index__ when only the second > is defined and asked to open a discussion on python-dev before making any change > "as the closest equivalent we have to this right now is the "negative" derivation, > where overriding __eq__ without overriding __hash__ implicitly marks the derived > class as unhashable (look for "type->tp_hash = PyObject_HashNotImplemented;").". Reading this again now, it occurs to me that there's another developer experience improvement we already made along these lines in Python 3: "By default, __ne__() delegates to __eq__() and inverts the result unless it is NotImplemented. " [1] By contrast, the corresponding (and annoying) Python 2 behaviour was: "The truth of x==y does not imply that x!=y is false. Accordingly, when defining __eq__(), one should also define __ne__() so that the operators will behave as expected." [2] The only difference is that whereas the new `__ne__` delegation behaviour could just be defined directly in `object.__ne__()`, `object` doesn't implement `__int__` by default, so the delegating function would need to be injected into the type when it is defined (and that's the part that's similar to the `__hash__ = None` negative derivation). So +1 from me. Cheers, Nick. [1] https://docs.python.org/3/reference/datamodel.html#object.__ne__ [2] https://docs.python.org/2/reference/datamodel.html#object.__ne__ -- Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4