Use object.__hash__ for Node.__hash__

This fixes a regression in commit 60293416db that
changed the `__hash__` implementation of Node from the default pointer
hash, to a hash based on the node fields.

Since these fields contains list objects, they are not hashable, making
every call to `Node.__hash__` fail.

This breaks some third-party usage such as in `django-compressor`
(See: https://github.com/django-compressor/django-compressor/issues/1060)

This changed reverts the hash method back to using `object.__hash__` as
the hash implementation.
This commit is contained in:
Kristian Klette 2021-10-27 20:35:20 +02:00 committed by David Lord
parent c0130ea7dd
commit 9b96b4817a
No known key found for this signature in database
GPG Key ID: 7A1C87E3F5BC42A8
3 changed files with 6 additions and 2 deletions

View File

@ -11,6 +11,8 @@ Unreleased
when parsing values on Python 3.10. :pr:`1537`
- Improve async performance by avoiding checks for common types.
:issue:`1514`
- Revert change to ``hash(Node)`` behavior. Nodes are hashed by id
again :issue:`1521`
Version 3.0.2

View File

@ -241,8 +241,7 @@ class Node(metaclass=NodeType):
return tuple(self.iter_fields()) == tuple(other.iter_fields())
def __hash__(self) -> int:
return hash(tuple(self.iter_fields()))
__hash__ = object.__hash__
def __repr__(self) -> str:
args_str = ", ".join(f"{a}={getattr(self, a, None)!r}" for a in self.fields)

3
tests/test_nodes.py Normal file
View File

@ -0,0 +1,3 @@
def test_template_hash(env):
template = env.parse("hash test")
hash(template)