diff options
author | Jeroen Demeyer <J.Demeyer@UGent.be> | 2019-05-28 14:42:53 +0200 |
---|---|---|
committer | Petr Viktorin <encukou@gmail.com> | 2019-05-28 14:42:53 +0200 |
commit | eb65e2443ac21739baf6d373abc7b4638b9d6927 (patch) | |
tree | 2197fa4322a60cbe077dfb8c03e0287cd3baabd9 /Objects/typeobject.c | |
parent | 0811f2d81a12a3415dc2cb2744b41520c48d4db5 (diff) | |
download | cpython-git-eb65e2443ac21739baf6d373abc7b4638b9d6927.tar.gz |
bpo-36922: implement PEP-590 Py_TPFLAGS_METHOD_DESCRIPTOR (GH-13338)
Co-authored-by: Mark Shannon <mark@hotpy.org>
Diffstat (limited to 'Objects/typeobject.c')
-rw-r--r-- | Objects/typeobject.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c index fc809d36e1..06e045bd15 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -4950,7 +4950,7 @@ static void inherit_special(PyTypeObject *type, PyTypeObject *base) { - /* Copying basicsize is connected to the GC flags */ + /* Copying tp_traverse and tp_clear is connected to the GC flags */ if (!(type->tp_flags & Py_TPFLAGS_HAVE_GC) && (base->tp_flags & Py_TPFLAGS_HAVE_GC) && (!type->tp_traverse && !type->tp_clear)) { @@ -5165,6 +5165,15 @@ inherit_slots(PyTypeObject *type, PyTypeObject *base) } { COPYSLOT(tp_descr_get); + /* Inherit Py_TPFLAGS_METHOD_DESCRIPTOR if tp_descr_get was inherited, + * but only for extension types */ + if (base->tp_descr_get && + type->tp_descr_get == base->tp_descr_get && + !(type->tp_flags & Py_TPFLAGS_HEAPTYPE) && + (base->tp_flags & Py_TPFLAGS_METHOD_DESCRIPTOR)) + { + type->tp_flags |= Py_TPFLAGS_METHOD_DESCRIPTOR; + } COPYSLOT(tp_descr_set); COPYSLOT(tp_dictoffset); COPYSLOT(tp_init); |