Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c84f2c5

Browse files
committed
Documentation for the new PyArg_UnpackTuple() function.
1 parent e4616e6 commit c84f2c5

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

Doc/api/utilities.tex

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,53 @@ \section{Parsing arguments and building values
388388
purpose.
389389
\end{cfuncdesc}
390390

391+
\begin{cfuncdesc}{int}{PyArg_UnpackTuple}{PyObject *args, char *name,
392+
int min, int max, \moreargs}
393+
A simpler form of parameter retrieval which does not use a format
394+
string to specify the types of the arguments. Functions which use
395+
this method to retrieve their parameters should be declared as
396+
\constant{METH_VARARGS} in function or method tables. The tuple
397+
containing the actual parameters should be passed as \var{args}; it
398+
must actually be a tuple. The length of the tuple must be at least
399+
\var{min} and no more than \var{max}; \var{min} and \var{max} may be
400+
equal. Additional arguments must be passed to the function, each of
401+
which should be a pointer to a \ctype{PyObject*} variable; these
402+
will be filled in with the values from \var{args}; they will contain
403+
borrowed references. The variables which correspond to optional
404+
parameters not given by \var{args} will not be filled in; these
405+
should be initialized by the caller.
406+
This function returns true on success and false if \var{args} is not
407+
a tuple or contains the wrong number of elements; an exception will
408+
be set if there was a failure.
409+
410+
This is an example of the use of this function, taken from the
411+
sources for the \module{_weakref} helper module for weak references:
412+
413+
\begin{verbatim}
414+
static PyObject *
415+
weakref_ref(PyObject *self, PyObject *args)
416+
{
417+
PyObject *object;
418+
PyObject *callback = NULL;
419+
PyObject *result = NULL;
420+
421+
if (PyArg_UnpackTuple(args, "ref", 1, 2, &object, &callback)) {
422+
result = PyWeakref_NewRef(object, callback);
423+
}
424+
return result;
425+
}
426+
\end{verbatim}
427+
428+
The call to \cfunction{PyArg_UnpackTuple()} in this example is
429+
entirely equivalent to this call to \cfunction{PyArg_ParseTuple()}:
430+
431+
\begin{verbatim}
432+
PyArg_ParseTuple(args, "O|O:ref", &object, &callback)
433+
\end{verbatim}
434+
435+
\versionadded{2.2}
436+
\end{cfuncdesc}
437+
391438
\begin{cfuncdesc}{PyObject*}{Py_BuildValue}{char *format,
392439
\moreargs}
393440
Create a new value based on a format string similar to those

0 commit comments

Comments
 (0)