Author: Armin Rigo <[email protected]>
Branch: fix-descrmismatch-crash
Changeset: r97771:78855fca6aa9
Date: 2019-10-14 11:40 +0200
http://bitbucket.org/pypy/pypy/changeset/78855fca6aa9/
Log: Improve the error message by using the class name 'set-or-frozenset'
diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -419,6 +419,8 @@
@specialize.memo()
def wrappable_class_name(Class):
+ if 'exact_class_applevel_name' in Class.__dict__:
+ return Class.exact_class_applevel_name
try:
return Class.typedef.name
except AttributeError:
diff --git a/pypy/objspace/std/setobject.py b/pypy/objspace/std/setobject.py
--- a/pypy/objspace/std/setobject.py
+++ b/pypy/objspace/std/setobject.py
@@ -20,6 +20,7 @@
class W_BaseSetObject(W_Root):
typedef = None
+ exact_class_applevel_name = 'set-or-frozenset'
def __init__(self, space, w_iterable=None):
"""Initialize the set by taking ownership of 'setdata'."""
diff --git a/pypy/objspace/std/test/test_setobject.py
b/pypy/objspace/std/test/test_setobject.py
--- a/pypy/objspace/std/test/test_setobject.py
+++ b/pypy/objspace/std/test/test_setobject.py
@@ -1042,3 +1042,10 @@
f = frozenset([1, 2, 3])
f.__init__(4, 5, 6)
assert f == frozenset([1, 2, 3])
+
+ def test_error_message_wrong_self(self):
+ e = raises(TypeError, frozenset.copy, 42)
+ assert "frozenset" in str(e.value)
+ if hasattr(frozenset.copy, 'im_func'):
+ e = raises(TypeError, frozenset.copy.im_func, 42)
+ assert "'set-or-frozenset'" in str(e.value)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit