[pypy-commit] pypy py3.7: better error message for object.__new__
cfbolz
pypy.commits at gmail.com
Mon Jan 6 14:50:01 EST 2020
Author: Carl Friedrich Bolz-Tereick <cfbolz at gmx.de>
Branch: py3.7
Changeset: r98464:4887e271842a
Date: 2020-01-06 20:49 +0100
http://bitbucket.org/pypy/pypy/changeset/4887e271842a/
Log: better error message for object.__new__
diff --git a/pypy/objspace/std/objectobject.py b/pypy/objspace/std/objectobject.py
--- a/pypy/objspace/std/objectobject.py
+++ b/pypy/objspace/std/objectobject.py
@@ -109,7 +109,7 @@
if (w_parent_init is space.w_object or
w_parent_new is not space.w_object):
raise oefmt(space.w_TypeError,
- "object() takes no parameters")
+ "%s() takes no parameters", w_type.name)
if w_type.is_abstract():
_abstract_method_error(space, w_type)
return space.allocate_instance(W_ObjectObject, w_type)
diff --git a/pypy/objspace/std/test/test_obj.py b/pypy/objspace/std/test/test_obj.py
--- a/pypy/objspace/std/test/test_obj.py
+++ b/pypy/objspace/std/test/test_obj.py
@@ -366,6 +366,14 @@
object.__init_subclass__() # does not crash
raises(TypeError, object.__init_subclass__, 1)
+ def test_better_error_init(self):
+ class A: pass
+
+ with raises(TypeError) as excinfo:
+ A(1)
+ assert "A() takes no parameters" in str(excinfo.value)
+
+
def test_isinstance_shortcut():
from pypy.objspace.std import objspace
space = objspace.StdObjSpace()
More information about the pypy-commit
mailing list