[pypy-commit] pypy default: Fix for test_descr.

alex_gaynor noreply at buildbot.pypy.org
Sat Oct 1 19:59:13 CEST 2011


Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch: 
Changeset: r47756:ad26a4fa9d67
Date: 2011-10-01 13:58 -0400
http://bitbucket.org/pypy/pypy/changeset/ad26a4fa9d67/

Log:	Fix for test_descr.

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
@@ -132,6 +132,19 @@
 
         assert A("hello") is str
 
+        # Make sure type(x) doesn't call x.__class__.__init__
+        class T(type):
+            counter = 0
+            def __init__(self, *args):
+                T.counter += 1
+        class C:
+            __metaclass__ = T
+        assert T.counter == 1
+        a = C()
+        assert T.counter == 1
+        assert type(a) is C
+        assert T.counter == 1
+
     def test_bases(self):
         assert int.__bases__ == (object,)
         class 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
@@ -848,7 +848,13 @@
         call_init = space.isinstance_w(w_newobject, w_type)
 
     # maybe invoke the __init__ of the type
-    if call_init:
+    try:
+        __args__.fixedunpack(1)
+    except ValueError:
+        single_arg = False
+    else:
+        single_arg = True
+    if call_init and not (space.is_w(w_type, space.w_type) and single_arg):
         w_descr = space.lookup(w_newobject, '__init__')
         w_result = space.get_and_call_args(w_descr, w_newobject, __args__)
         if not space.is_w(w_result, space.w_None):


More information about the pypy-commit mailing list