Skip to content

bpo-36974: inherit tp_vectorcall_offset unconditionally #13858

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 24, 2019
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
9 changes: 9 additions & 0 deletions Lib/test/test_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,9 +577,18 @@ class MethodDescriptorOverridden(_testcapi.MethodDescriptorBase):
def __call__(self, n):
return 'new'

class SuperBase:
def __call__(self, *args):
return super().__call__(*args)

class MethodDescriptorSuper(SuperBase, _testcapi.MethodDescriptorBase):
def __call__(self, *args):
return super().__call__(*args)

calls += [
(MethodDescriptorHeap(), (0,), {}, True),
(MethodDescriptorOverridden(), (0,), {}, 'new'),
(MethodDescriptorSuper(), (0,), {}, True),
]

for (func, args, kwargs, expected) in calls:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The slot ``tp_vectorcall_offset`` is inherited unconditionally to support
``super().__call__()`` when the base class uses vectorcall.
2 changes: 1 addition & 1 deletion Objects/call.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ PyVectorcall_Call(PyObject *callable, PyObject *tuple, PyObject *kwargs)
/* get vectorcallfunc as in _PyVectorcall_Function, but without
* the _Py_TPFLAGS_HAVE_VECTORCALL check */
Py_ssize_t offset = Py_TYPE(callable)->tp_vectorcall_offset;
if ((offset <= 0) || (!Py_TYPE(callable)->tp_call)) {
if (offset <= 0) {
PyErr_Format(PyExc_TypeError, "'%.200s' object does not support vectorcall",
Py_TYPE(callable)->tp_name);
return NULL;
Expand Down
12 changes: 6 additions & 6 deletions Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -5148,15 +5148,15 @@ inherit_slots(PyTypeObject *type, PyTypeObject *base)
COPYSLOT(tp_repr);
/* tp_hash see tp_richcompare */
{
/* Inherit tp_vectorcall_offset only if tp_call is not overridden */
if (!type->tp_call) {
COPYSLOT(tp_vectorcall_offset);
}
/* Inherit_Py_TPFLAGS_HAVE_VECTORCALL for non-heap types
/* Always inherit tp_vectorcall_offset to support PyVectorcall_Call().
* If _Py_TPFLAGS_HAVE_VECTORCALL is not inherited, then vectorcall
* won't be used automatically. */
COPYSLOT(tp_vectorcall_offset);

/* Inherit _Py_TPFLAGS_HAVE_VECTORCALL for non-heap types
* if tp_call is not overridden */
if (!type->tp_call &&
(base->tp_flags & _Py_TPFLAGS_HAVE_VECTORCALL) &&
!(type->tp_flags & _Py_TPFLAGS_HAVE_VECTORCALL) &&
!(type->tp_flags & Py_TPFLAGS_HEAPTYPE))
{
type->tp_flags |= _Py_TPFLAGS_HAVE_VECTORCALL;
Expand Down