Skip to content

Commit 85dd0c9

Browse files
committed
PEP 590: update
1 parent 669b630 commit 85dd0c9

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

pep-0590.rst

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ Calls are made through a function pointer taking the following parameters:
5555
* ``PyObject *callable``: The called object
5656
* ``Py_ssize_t n``: The number of arguments plus the optional flag ``PY_VECTORCALL_ARGUMENTS_OFFSET`` (see below)
5757
* ``PyObject *const *args``: A vector of arguments
58-
* ``PyTupleObject *kwnames``: A tuple of the names of the named arguments.
58+
* ``PyObject *kwnames``: Either ``NULL`` or a non-empty tuple of the names of the keyword arguments
5959

6060
This is implemented by the function pointer type:
6161
``typedef PyObject *(*vectorcallfunc)(PyObject *callable, Py_ssize_t n, PyObject *const *args, PyObject *kwnames);``
@@ -99,11 +99,13 @@ The call
9999
The call takes the form ``((vectorcallfunc)(((char *)o)+offset))(o, n, args, kwnames)`` where
100100
``offset`` is ``Py_TYPE(o)->tp_vectorcall_offset``.
101101
The caller is responsible for creating the ``kwnames`` tuple and ensuring that there are no duplicates in it.
102+
For efficiently dealing with the common case of no keywords,
103+
``kwnames`` must be ``NULL`` if there are no keyword arguments.
102104

103105
``n`` is the number of postional arguments plus possibly the ``PY_VECTORCALL_ARGUMENTS_OFFSET`` flag.
104106

105107
PY_VECTORCALL_ARGUMENTS_OFFSET
106-
------------------------------
108+
---------------------
107109

108110
The flag ``PY_VECTORCALL_ARGUMENTS_OFFSET`` should be added to ``n``
109111
if the callee is allowed to temporarily change ``args[-1]``.
@@ -131,8 +133,8 @@ The following functions or macros are added to the C API:
131133
Calls ``obj`` with the given arguments.
132134
Note that ``nargs`` may include the flag ``PY_VECTORCALL_ARGUMENTS_OFFSET``.
133135
The actual number of positional arguments is given by ``PyVectorcall_NARGS(nargs)``.
134-
The argument ``keywords`` is a tuple of keyword names or ``NULL``.
135-
An empty tuple has the same effect as passing ``NULL``.
136+
The argument ``keywords`` is either a dict, a tuple of keyword names or ``NULL``.
137+
An empty dict or empty tuple has the same effect as passing ``NULL``.
136138
This uses either the vectorcall protocol or ``tp_call`` internally;
137139
if neither is supported, an exception is raised.
138140

@@ -149,7 +151,7 @@ New ``METH_VECTORCALL`` flag
149151
----------------------------
150152

151153
A new constant ``METH_VECTORCALL`` is added for specifying ``PyMethodDef`` structs.
152-
It means that the C function has the type ``PyObject *(*call) (PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwname)``.
154+
It means that the C function has the signature ``vectorcallfunc``.
153155
This should be the preferred flag for new functions, as this avoids a wrapper function.
154156

155157
**NOTE**: the numerical value of ``METH_VECTORCALL`` is unspecified
@@ -205,7 +207,7 @@ The ``PyMethodDef`` protocol and Argument Clinic
205207

206208
Argument Clinic [4]_ automatically generates wrapper functions around lower-level callables, providing safe unboxing of primitive types and
207209
other safety checks.
208-
Argument Clinic could be extended to generate wrapper objects conforming to the new ``vectorcall`` protocol.
210+
Argument Clinic could be extended to generate wrapper objects with the ``METH_VECTORCALL`` signature.
209211
This will allow execution to flow from the caller to the Argument Clinic generated wrapper and
210212
thence to the hand-written code with only a single indirection.
211213

0 commit comments

Comments
 (0)