[pypy-commit] pypy identity-dict-strategy: invalidate the cache when the type is mutated
antocuni
noreply at buildbot.pypy.org
Tue Jul 19 18:44:19 CEST 2011
Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: identity-dict-strategy
Changeset: r45741:62b65edc5a4b
Date: 2011-07-19 17:09 +0200
http://bitbucket.org/pypy/pypy/changeset/62b65edc5a4b/
Log: invalidate the cache when the type is mutated
diff --git a/pypy/objspace/std/test/test_typeobject.py b/pypy/objspace/std/test/test_typeobject.py
--- a/pypy/objspace/std/test/test_typeobject.py
+++ b/pypy/objspace/std/test/test_typeobject.py
@@ -1228,8 +1228,20 @@
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)
diff --git a/pypy/objspace/std/typeobject.py b/pypy/objspace/std/typeobject.py
--- a/pypy/objspace/std/typeobject.py
+++ b/pypy/objspace/std/typeobject.py
@@ -155,6 +155,7 @@
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
@@ -162,6 +163,10 @@
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
More information about the pypy-commit
mailing list