DeprecationWarning: Overriding __eq__ blocks inheritance of __hash__ in
3.x
--
Ticket URL: <https://code.djangoproject.com/ticket/26083>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
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:
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`
--
Comment:
Can you point to where the errors are coming from? I'm not aware of any
deprecation warnings when running Django's test suite.
--
Ticket URL: <https://code.djangoproject.com/ticket/26083#comment:1>
Comment (by atombrella):
/home/mads/djangorestframework/local/lib/python2.7/site-
packages/django/db/__init__.py:29: DeprecationWarning: Overriding __eq__
blocks inheritance of __hash__ in 3.x
class DefaultConnectionProxy(object):
/home/mads/djangorestframework/local/lib/python2.7/site-
packages/django/core/validators.py:31: DeprecationWarning: Overriding
__eq__ blocks inheritance of __hash__ in 3.x
class RegexValidator(object):
/home/mads/djangorestframework/local/lib/python2.7/site-
packages/django/core/validators.py:151: DeprecationWarning: Overriding
__eq__ blocks inheritance of __hash__ in 3.x
class EmailValidator(object):
/home/mads/djangorestframework/local/lib/python2.7/site-
packages/django/core/validators.py:289: DeprecationWarning: Overriding
__eq__ blocks inheritance of __hash__ in 3.x
class BaseValidator(object):
/home/mads/djangorestframework/local/lib/python2.7/site-
packages/django/core/validators.py:352: DeprecationWarning: Overriding
__eq__ blocks inheritance of __hash__ in 3.x
class DecimalValidator(object):
/home/mads/djangorestframework/local/lib/python2.7/site-
packages/django/core/checks/messages.py:15: DeprecationWarning: Overriding
__eq__ blocks inheritance of __hash__ in 3.x
class CheckMessage(object):
/home/mads/djangorestframework/local/lib/python2.7/site-
packages/django/core/cache/__init__.py:90: DeprecationWarning: Overriding
__eq__ blocks inheritance of __hash__ in 3.x
class DefaultCacheProxy(object):
/home/mads/djangorestframework/local/lib/python2.7/site-
packages/django/db/models/sql/datastructures.py:28: DeprecationWarning:
Overriding __eq__ blocks inheritance of __hash__ in 3.x
class Join(object):
/home/mads/djangorestframework/local/lib/python2.7/site-
packages/django/template/context.py:32: DeprecationWarning: Overriding
__eq__ blocks inheritance of __hash__ in 3.x
class BaseContext(object):
/home/mads/djangorestframework/local/lib/python2.7/site-
packages/django/template/base.py:138: DeprecationWarning: Overriding
__eq__ blocks inheritance of __hash__ in 3.x
class Origin(object):
--
Ticket URL: <https://code.djangoproject.com/ticket/26083#comment:2>
* stage: Unreviewed => Accepted
Comment:
From what I read [http://stackoverflow.com/questions/15471333/how-to-
eliminate-a-python3-deprecation-warning-for-the-equality-operator on
stackoverflow], the lack of `__hash__()` is only a problem if these
objects are used in something like a `set()`, which seems unlikely in
these cases which is why we haven't had any report of problems, I suppose.
If I could at least reproduce the warnings I would find some value in
fixing them, but I can't.
--
Ticket URL: <https://code.djangoproject.com/ticket/26083#comment:3>
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>
Comment (by benf-wspdigital):
The original reporter discovered these warnings by running the test suite
for the ‘django-rest-framework‘ library.
I have followed the instructions for [http://www.django-rest-
framework.org/topics/contributing/#testing running the test suite for
django-rest-framework], and got the same warnings originally reported in
the Django code base:
{{{
$ python2 -3 -Wall ./runtests.py -q --fast
[…]
/Users/benfinney/.virtualenvs/test-install/lib/python2.7/site-
packages/django/core/checks/messages.py:15: DeprecationWarning: Overriding
__eq__ blocks inheritance of __hash__ in 3.x
class CheckMessage(object):
/Users/benfinney/.virtualenvs/test-install/lib/python2.7/site-
packages/django/core/cache/__init__.py:90: DeprecationWarning: Overriding
__eq__ blocks inheritance of __hash__ in 3.x
class DefaultCacheProxy(object):
/Users/benfinney/.virtualenvs/test-install/lib/python2.7/site-
packages/django/db/__init__.py:29: DeprecationWarning: Overriding __eq__
blocks inheritance of __hash__ in 3.x
class DefaultConnectionProxy(object):
/Users/benfinney/.virtualenvs/test-install/lib/python2.7/site-
packages/django/core/validators.py:31: DeprecationWarning: Overriding
__eq__ blocks inheritance of __hash__ in 3.x
class RegexValidator(object):
/Users/benfinney/.virtualenvs/test-install/lib/python2.7/site-
packages/django/core/validators.py:158: DeprecationWarning: Overriding
__eq__ blocks inheritance of __hash__ in 3.x
class EmailValidator(object):
/Users/benfinney/.virtualenvs/test-install/lib/python2.7/site-
packages/django/core/validators.py:296: DeprecationWarning: Overriding
__eq__ blocks inheritance of __hash__ in 3.x
class BaseValidator(object):
/Users/benfinney/.virtualenvs/test-install/lib/python2.7/site-
packages/django/core/validators.py:359: DeprecationWarning: Overriding
__eq__ blocks inheritance of __hash__ in 3.x
class DecimalValidator(object):
/Users/benfinney/.virtualenvs/test-install/lib/python2.7/site-
packages/django/db/models/sql/datastructures.py:28: DeprecationWarning:
Overriding __eq__ blocks inheritance of __hash__ in 3.x
class Join(object):
/Users/benfinney/.virtualenvs/test-install/lib/python2.7/site-
packages/django/template/context.py:32: DeprecationWarning: Overriding
__eq__ blocks inheritance of __hash__ in 3.x
class BaseContext(object):
/Users/benfinney/.virtualenvs/test-install/lib/python2.7/site-
packages/django/template/base.py:138: DeprecationWarning: Overriding
__eq__ blocks inheritance of __hash__ in 3.x
class Origin(object):
[…]
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26083#comment:5>
* status: new => closed
* resolution: => wontfix
Comment:
At this point Django doesn't support Python 2 in master so silencing the
warnings is no longer a reason to address this ticket. Absent a use case
where the lack of `__hash__()` causes a problem for usage of these
classes, I think it's fine to close this ticket.
--
Ticket URL: <https://code.djangoproject.com/ticket/26083#comment:6>