File tree 1 file changed +8
-2
lines changed
1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -226,7 +226,7 @@ class Node:
226
226
"""AST nodes"""
227
227
228
228
# allow custom attributes and weak references (not used internally)
229
- __slots__ = "__dict__" , "__weakref__" , "loc"
229
+ __slots__ = "__dict__" , "__weakref__" , "loc" , "_hash"
230
230
231
231
loc : Optional [Location ]
232
232
@@ -255,7 +255,13 @@ def __eq__(self, other: Any) -> bool:
255
255
)
256
256
257
257
def __hash__ (self ) -> int :
258
- return hash (tuple (getattr (self , key ) for key in self .keys ))
258
+ if getattr (self , "_hash" , None ) is None :
259
+ self ._hash = hash (tuple (getattr (self , key ) for key in self .keys ))
260
+ return self ._hash
261
+
262
+ def __setattr__ (self , key , value ):
263
+ object .__setattr__ (self , "_hash" , None )
264
+ super ().__setattr__ (key , value )
259
265
260
266
def __copy__ (self ) -> "Node" :
261
267
"""Create a shallow copy of the node."""
You can’t perform that action at this time.
0 commit comments