Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3edac31

Browse filesBrowse files
python/cpython#64658: Expand Argument Clinic return converter docs (python/cpython#104175)
1 parent 2e689ce commit 3edac31
Copy full SHA for 3edac31

File tree

Expand file treeCollapse file tree

1 file changed

+28
-13
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+28
-13
lines changed

‎Doc/howto/clinic.rst

Copy file name to clipboardExpand all lines: Doc/howto/clinic.rst
+28-13Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,19 +1033,36 @@ you're not permitted to use:
10331033
Using a return converter
10341034
------------------------
10351035

1036-
By default the impl function Argument Clinic generates for you returns ``PyObject *``.
1037-
But your C function often computes some C type, then converts it into the ``PyObject *``
1036+
By default, the impl function Argument Clinic generates for you returns
1037+
:c:type:`PyObject * <PyObject>`.
1038+
But your C function often computes some C type,
1039+
then converts it into the :c:type:`!PyObject *`
10381040
at the last moment. Argument Clinic handles converting your inputs from Python types
10391041
into native C types—why not have it convert your return value from a native C type
10401042
into a Python type too?
10411043

10421044
That's what a "return converter" does. It changes your impl function to return
10431045
some C type, then adds code to the generated (non-impl) function to handle converting
1044-
that value into the appropriate ``PyObject *``.
1046+
that value into the appropriate :c:type:`!PyObject *`.
10451047

10461048
The syntax for return converters is similar to that of parameter converters.
10471049
You specify the return converter like it was a return annotation on the
1048-
function itself. Return converters behave much the same as parameter converters;
1050+
function itself, using ``->`` notation.
1051+
1052+
For example:
1053+
1054+
.. code-block:: c
1055+
1056+
/*[clinic input]
1057+
add -> int
1058+
1059+
a: int
1060+
b: int
1061+
/
1062+
1063+
[clinic start generated code]*/
1064+
1065+
Return converters behave much the same as parameter converters;
10491066
they take arguments, the arguments are all keyword-only, and if you're not changing
10501067
any of the default arguments you can omit the parentheses.
10511068

@@ -1066,19 +1083,17 @@ Currently Argument Clinic supports only a few return converters:
10661083
.. code-block:: none
10671084
10681085
bool
1086+
double
1087+
float
10691088
int
1070-
unsigned int
10711089
long
1072-
unsigned int
1073-
size_t
10741090
Py_ssize_t
1075-
float
1076-
double
1077-
DecodeFSDefault
1091+
size_t
1092+
unsigned int
1093+
unsigned long
10781094
1079-
None of these take parameters. For the first three, return -1 to indicate
1080-
error. For ``DecodeFSDefault``, the return type is ``const char *``; return a ``NULL``
1081-
pointer to indicate an error.
1095+
None of these take parameters.
1096+
For all of these, return ``-1`` to indicate error.
10821097

10831098
To see all the return converters Argument Clinic supports, along with
10841099
their parameters (if any),

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.