File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -279,7 +279,8 @@ def __eq__(self, other):
279279 # because dictionaries are not hashable.
280280 and self .__globals__ is other .__globals__
281281 and self .__forward_is_class__ == other .__forward_is_class__
282- and self .__cell__ == other .__cell__
282+ # Two separate cells are always considered unequal in forward refs.
283+ and self .__cell__ is other .__cell__
283284 and self .__owner__ == other .__owner__
284285 and (
285286 (tuple (sorted (self .__extra_names__ .items ())) if self .__extra_names__ else None ) ==
@@ -293,7 +294,10 @@ def __hash__(self):
293294 self .__forward_module__ ,
294295 id (self .__globals__ ), # dictionaries are not hashable, so hash by identity
295296 self .__forward_is_class__ ,
296- tuple (sorted (self .__cell__ .items ())) if isinstance (self .__cell__ , dict ) else self .__cell__ ,
297+ ( # cells are mutable and not hashable as well
298+ tuple (sorted ([(name , id (cell )) for name , cell in self .__cell__ .items ()]))
299+ if isinstance (self .__cell__ , dict ) else id (self .__cell__ ),
300+ ),
297301 self .__owner__ ,
298302 tuple (sorted (self .__extra_names__ .items ())) if self .__extra_names__ else None ,
299303 ))
You can’t perform that action at this time.
0 commit comments