[pypy-svn] r78308 - in pypy/trunk/pypy/objspace/std: . test
cfbolz at codespeak.net
cfbolz at codespeak.net
Tue Oct 26 18:12:17 CEST 2010
Author: cfbolz
Date: Tue Oct 26 18:12:15 2010
New Revision: 78308
Modified:
pypy/trunk/pypy/objspace/std/test/test_mapdict.py
pypy/trunk/pypy/objspace/std/test/test_shadowtracking.py
pypy/trunk/pypy/objspace/std/test/test_versionedtype.py
pypy/trunk/pypy/objspace/std/typeobject.py
Log:
(arigo, cfbolz): after some discussion we decided that a custom metaclass
doesn't interfere with versiontag.
Modified: pypy/trunk/pypy/objspace/std/test/test_mapdict.py
==============================================================================
--- pypy/trunk/pypy/objspace/std/test/test_mapdict.py (original)
+++ pypy/trunk/pypy/objspace/std/test/test_mapdict.py Tue Oct 26 18:12:15 2010
@@ -753,6 +753,25 @@
return a.x
#
res = self.check(f, 'x')
+ assert res == (1, 0, 0)
+ res = self.check(f, 'x')
+ assert res == (0, 1, 0)
+ res = self.check(f, 'x')
+ assert res == (0, 1, 0)
+
+ def test_old_style_base(self):
+ class B:
+ pass
+ class C(object):
+ pass
+ class A(C, B):
+ pass
+ a = A()
+ a.x = 42
+ def f():
+ return a.x
+ #
+ res = self.check(f, 'x')
assert res == (0, 0, 1)
res = self.check(f, 'x')
assert res == (0, 0, 1)
Modified: pypy/trunk/pypy/objspace/std/test/test_shadowtracking.py
==============================================================================
--- pypy/trunk/pypy/objspace/std/test/test_shadowtracking.py (original)
+++ pypy/trunk/pypy/objspace/std/test/test_shadowtracking.py Tue Oct 26 18:12:15 2010
@@ -140,10 +140,11 @@
def test_class_that_cannot_be_cached(self):
import __pypy__
- class metatype(type):
+ class X:
pass
- class A(object):
- __metaclass__ = metatype
+ class Y(object):
+ pass
+ class A(Y, X):
def f(self):
return 42
@@ -241,3 +242,21 @@
foo = 3
D.__bases__ = (C, F)
assert e.foo == 3
+
+ def test_custom_metaclass(self):
+ import __pypy__
+ class MetaA(type):
+ def __getattribute__(self, x):
+ return 1
+ def f(self):
+ return 42
+ A = type.__new__(MetaA, "A", (), {"f": f})
+ l = [type.__getattribute__(A, "__new__")(A)] * 10
+ __pypy__.reset_method_cache_counter()
+ for i, a in enumerate(l):
+ assert a.f() == 42
+ cache_counter = __pypy__.method_cache_counter("f")
+ assert cache_counter[0] >= 5
+ assert cache_counter[1] >= 1 # should be (27, 3)
+ assert sum(cache_counter) == 10
+
Modified: pypy/trunk/pypy/objspace/std/test/test_versionedtype.py
==============================================================================
--- pypy/trunk/pypy/objspace/std/test/test_versionedtype.py (original)
+++ pypy/trunk/pypy/objspace/std/test/test_versionedtype.py Tue Oct 26 18:12:15 2010
@@ -12,10 +12,12 @@
def f(self): pass
class B(A):
pass
- class metatype(type):
+ class X:
+ pass
+ class Y(object):
+ pass
+ class C(Y, X):
pass
- class C(object):
- __metaclass__ = metatype
return A, B, C
""")
return space.unpackiterable(w_types)
Modified: pypy/trunk/pypy/objspace/std/typeobject.py
==============================================================================
--- pypy/trunk/pypy/objspace/std/typeobject.py (original)
+++ pypy/trunk/pypy/objspace/std/typeobject.py Tue Oct 26 18:12:15 2010
@@ -104,14 +104,12 @@
if overridetypedef is not None:
setup_builtin_type(w_self)
- custom_metaclass = False
else:
setup_user_defined_type(w_self)
- custom_metaclass = not space.is_w(space.type(w_self), space.w_type)
w_self.w_same_layout_as = get_parent_layout(w_self)
if space.config.objspace.std.withtypeversion:
- if custom_metaclass or not is_mro_purely_of_types(w_self.mro_w):
+ if not is_mro_purely_of_types(w_self.mro_w):
pass
else:
# the _version_tag should change, whenever the content of
More information about the Pypy-commit
mailing list