Skip to content

Commit ff81d6a

Browse files
committed
Use appropriate semantics in __eq__
1 parent 9194bbf commit ff81d6a

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

Lib/annotationlib.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,12 @@ def __eq__(self, other):
280280
and self.__globals__ is other.__globals__
281281
and self.__forward_is_class__ == other.__forward_is_class__
282282
# Two separate cells are always considered unequal in forward refs.
283-
and self.__cell__ is other.__cell__
283+
and (
284+
dict(zip(self.__cell__, map(id, self.__cell__.values())))
285+
== dict(zip(other.__cell__, map(id, other.__cell__.values())))
286+
if isinstance(self.__cell__, dict) and isinstance(other.__cell__, dict)
287+
else self.__cell__ is other.__cell__
288+
)
284289
and self.__owner__ == other.__owner__
285290
and (
286291
(tuple(sorted(self.__extra_names__.items())) if self.__extra_names__ else None) ==
@@ -294,7 +299,7 @@ def __hash__(self):
294299
self.__forward_module__,
295300
id(self.__globals__), # dictionaries are not hashable, so hash by identity
296301
self.__forward_is_class__,
297-
( # cells are mutable and not hashable as well
302+
( # cells are not hashable as well
298303
tuple(sorted([(name, id(cell)) for name, cell in self.__cell__.items()]))
299304
if isinstance(self.__cell__, dict) else id(self.__cell__),
300305
),

0 commit comments

Comments
 (0)