Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Lib/test/test_descr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Slot functions optimize any callable with ``Py_TPFLAGS_METHOD_DESCRIPTOR`` instead of only instances of ``function``.
2 changes: 1 addition & 1 deletion Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down