Skip to content
Myr

Use object.__hash__ for Node.__hash__

Before adoption: this commit came in with the history the project adopted, so no landing records it.

This fixes a regression in commit 60293416db69782fd048a7820667afa4ae7c423b 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.

authored by Kristian Klette · committed by David Lord · parent c0130ea · Browse files · 3 files+6 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+6 added−2 removed

  • tests:+3 added−0 removed
  • other:+3 added−2 removed

3 files+6 added−2 removed

modified:src/jinja2/nodes.py+1 added-2 removed
239 unmodified lines
240 return NotImplemented241242 return tuple(self.iter_fields()) == tuple(other.iter_fields())243244 def __hash__(self) -> int:245 return hash(tuple(self.iter_fields()))244 __hash__ = object.__hash__245246 def __repr__(self) -> str:247 args_str = ", ".join(f"{a}={getattr(self, a, None)!r}" for a in self.fields)248 return f"{type(self).__name__}({args_str})"
956 unmodified lines
added:tests/test_nodes.py+3 added
1def test_template_hash(env):2 template = env.parse("hash test")3 hash(template)
modified:CHANGES.rst+2 added
9 unmodified lines
10- Fix how the native environment treats leading and trailing spaces11 when parsing values on Python 3.10. :pr:`1537`12- Improve async performance by avoiding checks for common types.13 :issue:`1514`14- Revert change to ``hash(Node)`` behavior. Nodes are hashed by id15 again :issue:`1521`161718Version 3.0.219-------------
894 unmodified lines