bpo-36922: use Py_TPFLAGS_METHOD_DESCRIPTOR in lookup_maybe_method() (GH-13865)

(cherry picked from commit 2e9954d347)

Co-authored-by: Jeroen Demeyer <J.Demeyer@UGent.be>
This commit is contained in:
Miss Islington (bot) 2019-06-17 05:12:42 -07:00 committed by GitHub
parent a5ddbfbf50
commit 988fff5d0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 1 deletions

View File

@ -4647,9 +4647,11 @@ order (MRO) for bases """
def test_mixing_slot_wrappers(self):
class X(dict):
__setattr__ = dict.__setitem__
__neg__ = dict.copy
x = X()
x.y = 42
self.assertEqual(x["y"], 42)
self.assertEqual(x, -x)
def test_slot_shadows_class_variable(self):
with self.assertRaises(ValueError) as cm:

View File

@ -0,0 +1 @@
Slot functions optimize any callable with ``Py_TPFLAGS_METHOD_DESCRIPTOR`` instead of only instances of ``function``.

View File

@ -1412,7 +1412,7 @@ lookup_maybe_method(PyObject *self, _Py_Identifier *attrid, int *unbound)
return NULL;
}
if (PyFunction_Check(res)) {
if (PyType_HasFeature(Py_TYPE(res), Py_TPFLAGS_METHOD_DESCRIPTOR)) {
/* Avoid temporary PyMethodObject */
*unbound = 1;
Py_INCREF(res);