From 00e36e8fd9b78c6f491f8cdec3828a60998a67ee Mon Sep 17 00:00:00 2001 From: Jeroen Demeyer Date: Thu, 6 Jun 2019 15:47:13 +0200 Subject: [PATCH 1/2] bpo-36922: use Py_TPFLAGS_METHOD_DESCRIPTOR in lookup_maybe_method() --- Lib/test/test_descr.py | 2 ++ Objects/typeobject.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py index 6b018ccc56fa1d..9998a3cc77a223 100644 --- a/Lib/test/test_descr.py +++ b/Lib/test/test_descr.py @@ -4647,9 +4647,11 @@ class Foo: 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: diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 006df8d1f090d5..01e95aea61af96 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -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); From d11fc5edc8cdeb5e0911c552de18fea6d665692e Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" Date: Thu, 6 Jun 2019 13:59:54 +0000 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Core and Builtins/2019-06-06-13-59-52.bpo-36922.EMZ3TF.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2019-06-06-13-59-52.bpo-36922.EMZ3TF.rst diff --git a/Misc/NEWS.d/next/Core and Builtins/2019-06-06-13-59-52.bpo-36922.EMZ3TF.rst b/Misc/NEWS.d/next/Core and Builtins/2019-06-06-13-59-52.bpo-36922.EMZ3TF.rst new file mode 100644 index 00000000000000..c2a2ad4e8e7379 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2019-06-06-13-59-52.bpo-36922.EMZ3TF.rst @@ -0,0 +1 @@ +Slot functions optimize any callable with ``Py_TPFLAGS_METHOD_DESCRIPTOR`` instead of only instances of ``function``. \ No newline at end of file