mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
bpo-36922: use Py_TPFLAGS_METHOD_DESCRIPTOR in lookup_maybe_method() (GH-13865)
This commit is contained in:
parent
0456df4a55
commit
2e9954d347
3 changed files with 4 additions and 1 deletions
|
@ -4647,9 +4647,11 @@ order (MRO) for bases """
|
||||||
def test_mixing_slot_wrappers(self):
|
def test_mixing_slot_wrappers(self):
|
||||||
class X(dict):
|
class X(dict):
|
||||||
__setattr__ = dict.__setitem__
|
__setattr__ = dict.__setitem__
|
||||||
|
__neg__ = dict.copy
|
||||||
x = X()
|
x = X()
|
||||||
x.y = 42
|
x.y = 42
|
||||||
self.assertEqual(x["y"], 42)
|
self.assertEqual(x["y"], 42)
|
||||||
|
self.assertEqual(x, -x)
|
||||||
|
|
||||||
def test_slot_shadows_class_variable(self):
|
def test_slot_shadows_class_variable(self):
|
||||||
with self.assertRaises(ValueError) as cm:
|
with self.assertRaises(ValueError) as cm:
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Slot functions optimize any callable with ``Py_TPFLAGS_METHOD_DESCRIPTOR`` instead of only instances of ``function``.
|
|
@ -1412,7 +1412,7 @@ lookup_maybe_method(PyObject *self, _Py_Identifier *attrid, int *unbound)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PyFunction_Check(res)) {
|
if (PyType_HasFeature(Py_TYPE(res), Py_TPFLAGS_METHOD_DESCRIPTOR)) {
|
||||||
/* Avoid temporary PyMethodObject */
|
/* Avoid temporary PyMethodObject */
|
||||||
*unbound = 1;
|
*unbound = 1;
|
||||||
Py_INCREF(res);
|
Py_INCREF(res);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue