#26083: Python 2 deprecation warnings for classes that define __eq__() but not
__hash__()
--------------------------------------+------------------------------------
Reporter: atombrella | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Core (Other) | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Description changed by benf-wspdigital:
Old description:
> I ran `python -Werror runtests.py` for DRF, and noticed quite a lot of
> warnings about `__eq__` and `__hash__`, and then checked Django's
> repository.
>
> `DeprecationWarning: Overriding __eq__ blocks inheritance of __hash__ in
> 3.x`
New description:
Many classes within Django define the `__eq__` method, which in Python 3
will have disruptive implications for inheritance of `__hash__`. See the
[https://docs.python.org/3.4/reference/datamodel.html#object.__hash__
Python 3 documentation for `__hash__`]:
If a class does not define an __eq__() method it should not define a
__hash__() operation either; if it defines __eq__() but not __hash__(),
its instances will not be usable as items in hashable collections. […]
and continues on to describe in detail the implications of defining
`__eq__` and/or `__hash__`, and exactly why one would implement one and/or
the other on a class.
The warning emitted by `python2 -3` for this is:
DeprecationWarning: Overriding __eq__ blocks inheritance of __hash__
in 3.x
--
--
Ticket URL: <https://code.djangoproject.com/ticket/26083#comment:4>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/068.745441ffb748b3478c54c1c9354a6976%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.