[pypy-commit] pypy py3.6: can't use the one-argument form of type.__new__ for subclasses of type

cfbolz pypy.commits at gmail.com
Sat May 12 13:32:34 EDT 2018


Author: Carl Friedrich Bolz-Tereick <cfbolz at gmx.de>
Branch: py3.6
Changeset: r94535:7c4bb9c6272f
Date: 2018-05-12 19:19 +0200
http://bitbucket.org/pypy/pypy/changeset/7c4bb9c6272f/

Log:	can't use the one-argument form of type.__new__ for subclasses of
	type

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
@@ -1607,3 +1607,9 @@
 
         assert Y.kwargs == dict(a=1, b=2)
         """)
+
+    def test_onearg_type_only_for_type(self):
+        class Meta(type):
+            pass
+
+        raises(TypeError, Meta, 5)
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
@@ -759,10 +759,14 @@
 
     w_typetype = _precheck_for_new(space, w_typetype)
 
-    # special case for type(x)
-    if (space.is_w(space.type(w_typetype), space.w_type) and
-            len(__args__.arguments_w) == 1):
-        return space.type(w_name)
+    # special case for type(x), but not Metaclass(x)
+    if len(__args__.arguments_w) == 1:
+        if space.is_w(w_typetype, space.w_type):
+            return space.type(w_name)
+        else:
+            raise oefmt(space.w_TypeError,
+                        "%N.__new__() takes 3 arguments (1 given)",
+                        w_typetype)
     w_bases = __args__.arguments_w[1]
     w_dict = __args__.arguments_w[2]
     return _create_new_type(space, w_typetype, w_name, w_bases, w_dict, __args__)


More information about the pypy-commit mailing list