[pypy-commit] pypy unicode-utf8-py3: test, fix assigning to type qualname
mattip
pypy.commits at gmail.com
Tue Nov 13 03:20:00 EST 2018
Author: Matti Picus <matti.picus at gmail.com>
Branch: unicode-utf8-py3
Changeset: r95309:9b6e8faed6ae
Date: 2018-11-12 20:36 -0800
http://bitbucket.org/pypy/pypy/changeset/9b6e8faed6ae/
Log: test, fix assigning to type qualname
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
@@ -971,6 +971,14 @@
e = raises(TypeError, type, 'D', (), {'__qualname__': 42})
assert str(e.value) == "type __qualname__ must be a str, not int"
+ for v in (42, b'abc'):
+ try:
+ C.__qualname__ = v
+ except TypeError as e:
+ assert 'can only assign string' in str(e)
+ else:
+ assert False
+
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
@@ -885,6 +885,10 @@
w_type = _check(space, w_type)
if not w_type.is_heaptype():
raise oefmt(space.w_TypeError, "can't set %N.__qualname__", w_type)
+ if not space.isinstance_w(w_value, space.w_text):
+ raise oefmt(space.w_TypeError,
+ "can only assign string to %N.__name__, not '%T'",
+ w_type, w_value)
w_type.qualname = space.utf8_w(w_value)
def descr_get__mro__(space, w_type):
More information about the pypy-commit
mailing list