1. Christopher Lambacher
  2. pypy

Commits

Antonio Cuni  committed 62b65ed

invalidate the cache when the type is mutated

  • Participants
  • Parent commits a2ad836
  • Branches identity-dict-strategy

Comments (0)

Files changed (2)

File pypy/objspace/std/test/test_typeobject.py

View file
             def __hash__(self):
                 return 0
 
-
         assert self.compares_by_identity(Plain)
         assert not self.compares_by_identity(CustomEq)
         assert not self.compares_by_identity(CustomCmp)
         assert not self.compares_by_identity(CustomHash)
+
+    def test_modify_class(self):
+        def foo(self, *args):
+            pass
+
+        class X(object):
+            pass
+
+        assert self.compares_by_identity(X)
+        X.__eq__ = foo
+        assert not self.compares_by_identity(X)
+        del X.__eq__
+        assert self.compares_by_identity(X)

File pypy/objspace/std/typeobject.py

View file
         assert w_self.is_heaptype() or space.config.objspace.std.mutable_builtintypes
         if (not space.config.objspace.std.withtypeversion and
             not space.config.objspace.std.getattributeshortcut and
+            not space.config.objspace.std.trackcomparebyidentity and
             not space.config.objspace.std.newshortcut):
             return
 
             w_self.uses_object_getattribute = False
             # ^^^ conservative default, fixed during real usage
 
+        if space.config.objspace.std.trackcomparebyidentity:
+            w_self.overrides_hash_eq_or_cmp = True
+            # ^^^ conservative default, fixed during real usage
+
         if space.config.objspace.std.newshortcut:
             w_self.w_bltin_new = None