Author: Carl Friedrich Bolz-Tereick <[email protected]>
Branch: py3.6
Changeset: r94642:10f843fed291
Date: 2018-05-21 16:31 +0200
http://bitbucket.org/pypy/pypy/changeset/10f843fed291/

Log:    better error messages

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
@@ -1612,4 +1612,7 @@
         class Meta(type):
             pass
 
-        raises(TypeError, Meta, 5)
+        info = raises(TypeError, Meta, 5)
+        assert "takes exactly 3 arguments (1 given)" in str(info.value)
+        info = raises(TypeError, Meta, 5, 7)
+        assert "takes exactly 3 arguments (1 given)" in str(info.value)
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
@@ -752,8 +752,13 @@
 def descr__new__(space, w_typetype, __args__):
     """This is used to create user-defined classes only."""
     if len(__args__.arguments_w) not in (1, 3):
-        raise oefmt(space.w_TypeError,
-                    "type.__new__() takes 1 or 3 arguments")
+        if space.is_w(w_typetype, space.w_type):
+            raise oefmt(space.w_TypeError,
+                        "type.__new__() takes 1 or 3 arguments")
+        else:
+            raise oefmt(space.w_TypeError,
+                        "%N.__new__() takes exactly 3 arguments (1 given)",
+                        w_typetype)
 
     w_name = __args__.arguments_w[0]
 
@@ -765,7 +770,7 @@
             return space.type(w_name)
         else:
             raise oefmt(space.w_TypeError,
-                        "%N.__new__() takes 3 arguments (1 given)",
+                        "%N.__new__() takes exactly 3 arguments (1 given)",
                         w_typetype)
     w_bases = __args__.arguments_w[1]
     w_dict = __args__.arguments_w[2]
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to