cpython: 1a2b8398f045 (original) (raw)
Mercurial > cpython
changeset 103991:1a2b8398f045 3.6
Issue #28214: Now __set_name__ is looked up on the class instead of the instance. [#28214]
Serhiy Storchaka storchaka@gmail.com | |
---|---|
date | Wed, 21 Sep 2016 15:54:59 +0300 |
parents | 3ab4a374b5f0 |
children | 2a5280db601c b995b1f52975 |
files | Lib/test/test_subclassinit.py Misc/NEWS Objects/typeobject.c |
diffstat | 3 files changed, 22 insertions(+), 5 deletions(-)[+] [-] Lib/test/test_subclassinit.py 12 Misc/NEWS 3 Objects/typeobject.c 12 |
line wrap: on
line diff
--- a/Lib/test/test_subclassinit.py +++ b/Lib/test/test_subclassinit.py @@ -148,6 +148,18 @@ class Test(unittest.TestCase): class A: d = Descriptor()
- def test_set_name_lookup(self):
resolved = [][](#l1.8)
class NonDescriptor:[](#l1.9)
def __getattr__(self, name):[](#l1.10)
resolved.append(name)[](#l1.11)
class A:[](#l1.13)
d = NonDescriptor()[](#l1.14)
self.assertNotIn('__set_name__', resolved,[](#l1.16)
'__set_name__ is looked up in instance dict')[](#l1.17)
+ def test_set_name_init_subclass(self): class Descriptor: def set_name(self, owner, name):
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,9 @@ What's New in Python 3.6.0 beta 2 Core and Builtins ----------------- +- Issue #28214: Now set_name is looked up on the class instead of the
- Issue #27955: Fallback on reading /dev/urandom device when the getrandom() syscall fails with EPERM, for example when blocked by SECCOMP.
--- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -6990,19 +6990,21 @@ update_all_slots(PyTypeObject* type) static int set_names(PyTypeObject *type) {
- PyObject *key, *value, *set_name, *tmp; Py_ssize_t i = 0; while (PyDict_Next(type->tp_dict, &i, &key, &value)) {
if (PyObject_HasAttr(value, _PyUnicode_FromId(&PyId___set_name__))) {[](#l3.12)
tmp = PyObject_CallMethodObjArgs([](#l3.13)
value, _PyUnicode_FromId(&PyId___set_name__),[](#l3.14)
type, key, NULL);[](#l3.15)
set_name = lookup_maybe(value, &PyId___set_name__);[](#l3.16)
if (set_name != NULL) {[](#l3.17)
tmp = PyObject_CallFunctionObjArgs(set_name, type, key, NULL);[](#l3.18)
Py_DECREF(set_name);[](#l3.19) if (tmp == NULL)[](#l3.20) return -1;[](#l3.21) else[](#l3.22) Py_DECREF(tmp);[](#l3.23) }[](#l3.24)
else if (PyErr_Occurred())[](#l3.25)
} return 0;return -1;[](#l3.26)