diff -r 784fea019cab Lib/test/test_descr.py --- a/Lib/test/test_descr.py Wed Nov 09 18:57:00 2016 -0500 +++ b/Lib/test/test_descr.py Thu Nov 10 15:00:40 2016 +0800 @@ -1305,6 +1305,13 @@ else: self.fail("shouldn't be allowed to set a.foo") + class Q: + __slots__ = ["__qualname__"] + a = Q() + self.assertNotHasAttr(a, "__qualname__") + a.__qualname__ = "a" + self.assertEqual(a.__qualname__, "a") + class C1(W, D): __slots__ = [] a = C1() diff -r 784fea019cab Objects/typeobject.c --- a/Objects/typeobject.c Wed Nov 09 18:57:00 2016 -0500 +++ b/Objects/typeobject.c Thu Nov 10 15:00:40 2016 +0800 @@ -2444,7 +2444,10 @@ goto error; } PyList_SET_ITEM(newslots, j, tmp); - if (PyDict_GetItem(dict, tmp)) { + /* CPython inserts __qualname__ into the namespace when creating + a class and will be removed below. */ + if (PyDict_GetItem(dict, tmp) && + _PyUnicode_CompareWithId(tmp, &PyId___qualname__) != 0) { PyErr_Format(PyExc_ValueError, "%R in __slots__ conflicts with class variable", tmp);