Skip to content

Commit 2e9954d

Browse files
jdemeyermethane
authored andcommitted
bpo-36922: use Py_TPFLAGS_METHOD_DESCRIPTOR in lookup_maybe_method() (GH-13865)
1 parent 0456df4 commit 2e9954d

File tree

3 files changed

+4
-1
lines changed

3 files changed

+4
-1
lines changed

Lib/test/test_descr.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4647,9 +4647,11 @@ class Foo:
46474647
def test_mixing_slot_wrappers(self):
46484648
class X(dict):
46494649
__setattr__ = dict.__setitem__
4650+
__neg__ = dict.copy
46504651
x = X()
46514652
x.y = 42
46524653
self.assertEqual(x["y"], 42)
4654+
self.assertEqual(x, -x)
46534655

46544656
def test_slot_shadows_class_variable(self):
46554657
with self.assertRaises(ValueError) as cm:
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Slot functions optimize any callable with ``Py_TPFLAGS_METHOD_DESCRIPTOR`` instead of only instances of ``function``.

Objects/typeobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1412,7 +1412,7 @@ lookup_maybe_method(PyObject *self, _Py_Identifier *attrid, int *unbound)
14121412
return NULL;
14131413
}
14141414

1415-
if (PyFunction_Check(res)) {
1415+
if (PyType_HasFeature(Py_TYPE(res), Py_TPFLAGS_METHOD_DESCRIPTOR)) {
14161416
/* Avoid temporary PyMethodObject */
14171417
*unbound = 1;
14181418
Py_INCREF(res);

0 commit comments

Comments
 (0)