aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXiang Zhang <angwerzx@126.com>2017-03-08 11:18:49 +0800
committerGitHub <noreply@github.com>2017-03-08 11:18:49 +0800
commitc393ee858932f79bd6dabf31550f9a53ea90bc68 (patch)
treecd731aaacc73568a0781efab63ceef9e629bb0eb /Objects/typeobject.c
parentbpo-26915: Test identity first in membership operation in index() and count()... (diff)
downloadcpython-c393ee858932f79bd6dabf31550f9a53ea90bc68.tar.gz
cpython-c393ee858932f79bd6dabf31550f9a53ea90bc68.tar.bz2
cpython-c393ee858932f79bd6dabf31550f9a53ea90bc68.zip
bpo-24329: allow __qualname__ and __classcell__ in __slots__ (GH-495)
Diffstat (limited to 'Objects/typeobject.c')
-rw-r--r--Objects/typeobject.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 18b67c83258..d70ced04bfe 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -2478,11 +2478,17 @@ type_new(PyTypeObject *metatype, PyObject *args, PyObject *kwds)
}
PyList_SET_ITEM(newslots, j, tmp);
if (PyDict_GetItem(dict, tmp)) {
- PyErr_Format(PyExc_ValueError,
- "%R in __slots__ conflicts with class variable",
- tmp);
- Py_DECREF(newslots);
- goto error;
+ /* CPython inserts __qualname__ and __classcell__ (when needed)
+ into the namespace when creating a class. They will be deleted
+ below so won't act as class variables. */
+ if (!_PyUnicode_EqualToASCIIId(tmp, &PyId___qualname__) &&
+ !_PyUnicode_EqualToASCIIId(tmp, &PyId___classcell__)) {
+ PyErr_Format(PyExc_ValueError,
+ "%R in __slots__ conflicts with class variable",
+ tmp);
+ Py_DECREF(newslots);
+ goto error;
+ }
}
j++;
}