Author: Armin Rigo <[email protected]>
Branch: py3.5
Changeset: r90612:92ab105ad8e7
Date: 2017-03-09 18:11 +0100
http://bitbucket.org/pypy/pypy/changeset/92ab105ad8e7/
Log: improve error message
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
@@ -957,6 +957,9 @@
assert C.__name__ == 'A'
assert C.__qualname__ == 'C'
+ e = raises(TypeError, type, 'D', (), {'__qualname__': 42})
+ assert str(e.value) == "type __qualname__ must be a str, not int"
+
def test_compare(self):
class A(object):
pass
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
@@ -197,6 +197,10 @@
if self.flag_heaptype:
w_qualname = self.dict_w.pop('__qualname__', None)
if w_qualname is not None:
+ if not space.isinstance_w(w_qualname, space.w_unicode):
+ raise oefmt(space.w_TypeError,
+ "type __qualname__ must be a str, not %T",
+ w_qualname)
self.qualname = space.unicode_w(w_qualname)
else:
self.qualname = self.getname(space)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit