]> granicus.if.org Git - python/commitdiff
bpo-36922: use Py_TPFLAGS_METHOD_DESCRIPTOR in lookup_maybe_method() (GH-13865)
authorJeroen Demeyer <J.Demeyer@UGent.be>
Mon, 17 Jun 2019 11:53:21 +0000 (13:53 +0200)
committerInada Naoki <songofacandy@gmail.com>
Mon, 17 Jun 2019 11:53:20 +0000 (20:53 +0900)
Lib/test/test_descr.py
Misc/NEWS.d/next/Core and Builtins/2019-06-06-13-59-52.bpo-36922.EMZ3TF.rst [new file with mode: 0644]
Objects/typeobject.c

index 301a2d2a0fd29c5e5b6bbaf4c470be1172309eac..0b43549efb838c8546b8303c0310914f1fb80ea8 100644 (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:
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 (file)
index 0000000..c2a2ad4
--- /dev/null
@@ -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
index ba128a90778c65b43da9ccaeea1149eb37216867..e4952511e33a65ed5fea98e641223065ac0803bb 100644 (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);