Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/graphql/language/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ class Node:
"""AST nodes"""

# allow custom attributes and weak references (not used internally)
__slots__ = "__dict__", "__weakref__", "loc"
__slots__ = "__dict__", "__weakref__", "loc", "_hash"

loc: Optional[Location]

Expand Down Expand Up @@ -255,7 +255,13 @@ def __eq__(self, other: Any) -> bool:
)

def __hash__(self) -> int:
return hash(tuple(getattr(self, key) for key in self.keys))
if getattr(self, "_hash", None) is None:
self._hash = hash(tuple(getattr(self, key) for key in self.keys))
return self._hash

def __setattr__(self, key, value):
object.__setattr__(self, "_hash", None)
super().__setattr__(key, value)

def __copy__(self) -> "Node":
"""Create a shallow copy of the node."""
Expand Down