mirror of https://github.com/python/cpython
do safety checks on __qualname__ assignment
This commit is contained in:
parent
8afa7fa510
commit
2c05a2e01b
|
@ -4502,6 +4502,14 @@ order (MRO) for bases """
|
||||||
self.assertEqual(float.real.__qualname__, 'float.real')
|
self.assertEqual(float.real.__qualname__, 'float.real')
|
||||||
self.assertEqual(int.__add__.__qualname__, 'int.__add__')
|
self.assertEqual(int.__add__.__qualname__, 'int.__add__')
|
||||||
|
|
||||||
|
class X:
|
||||||
|
pass
|
||||||
|
with self.assertRaises(TypeError):
|
||||||
|
del X.__qualname__
|
||||||
|
|
||||||
|
self.assertRaises(TypeError, type.__dict__['__qualname__'].__set__,
|
||||||
|
str, 'Oink')
|
||||||
|
|
||||||
def test_qualname_dict(self):
|
def test_qualname_dict(self):
|
||||||
ns = {'__qualname__': 'some.name'}
|
ns = {'__qualname__': 'some.name'}
|
||||||
tp = type('Foo', (), ns)
|
tp = type('Foo', (), ns)
|
||||||
|
|
|
@ -12,6 +12,9 @@ What's New in Python 3.3.1?
|
||||||
Core and Builtins
|
Core and Builtins
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
|
- Fix segfaults on setting __qualname__ on builtin types and attempting to
|
||||||
|
delete it on any type.
|
||||||
|
|
||||||
- Issue #16271: Fix strange bugs that resulted from __qualname__ appearing in a
|
- Issue #16271: Fix strange bugs that resulted from __qualname__ appearing in a
|
||||||
class's __dict__ and on type.
|
class's __dict__ and on type.
|
||||||
|
|
||||||
|
|
|
@ -311,6 +311,8 @@ type_set_qualname(PyTypeObject *type, PyObject *value, void *context)
|
||||||
{
|
{
|
||||||
PyHeapTypeObject* et;
|
PyHeapTypeObject* et;
|
||||||
|
|
||||||
|
if (!check_set_special_type_attr(type, value, "__qualname__"))
|
||||||
|
return -1;
|
||||||
if (!PyUnicode_Check(value)) {
|
if (!PyUnicode_Check(value)) {
|
||||||
PyErr_Format(PyExc_TypeError,
|
PyErr_Format(PyExc_TypeError,
|
||||||
"can only assign string to %s.__qualname__, not '%s'",
|
"can only assign string to %s.__qualname__, not '%s'",
|
||||||
|
|
Loading…
Reference in New Issue