@@ -1025,19 +1025,36 @@ you're not permitted to use:
1025
1025
Using a return converter
1026
1026
------------------------
1027
1027
1028
- By default the impl function Argument Clinic generates for you returns ``PyObject * ``.
1029
- But your C function often computes some C type, then converts it into the ``PyObject * ``
1028
+ By default, the impl function Argument Clinic generates for you returns
1029
+ :c:type: `PyObject * <PyObject> `.
1030
+ But your C function often computes some C type,
1031
+ then converts it into the :c:type: `!PyObject * `
1030
1032
at the last moment. Argument Clinic handles converting your inputs from Python types
1031
1033
into native C types—why not have it convert your return value from a native C type
1032
1034
into a Python type too?
1033
1035
1034
1036
That's what a "return converter" does. It changes your impl function to return
1035
1037
some C type, then adds code to the generated (non-impl) function to handle converting
1036
- that value into the appropriate `` PyObject * ` `.
1038
+ that value into the appropriate :c:type: ` ! PyObject * `.
1037
1039
1038
1040
The syntax for return converters is similar to that of parameter converters.
1039
1041
You specify the return converter like it was a return annotation on the
1040
- function itself. Return converters behave much the same as parameter converters;
1042
+ function itself, using ``-> `` notation.
1043
+
1044
+ For example:
1045
+
1046
+ .. code-block :: c
1047
+
1048
+ /*[clinic input]
1049
+ add -> int
1050
+
1051
+ a: int
1052
+ b: int
1053
+ /
1054
+
1055
+ [clinic start generated code]*/
1056
+
1057
+ Return converters behave much the same as parameter converters;
1041
1058
they take arguments, the arguments are all keyword-only, and if you're not changing
1042
1059
any of the default arguments you can omit the parentheses.
1043
1060
@@ -1058,19 +1075,17 @@ Currently Argument Clinic supports only a few return converters:
1058
1075
.. code-block :: none
1059
1076
1060
1077
bool
1078
+ double
1079
+ float
1061
1080
int
1062
- unsigned int
1063
1081
long
1064
- unsigned int
1065
- size_t
1066
1082
Py_ssize_t
1067
- float
1068
- double
1069
- DecodeFSDefault
1083
+ size_t
1084
+ unsigned int
1085
+ unsigned long
1070
1086
1071
- None of these take parameters. For the first three, return -1 to indicate
1072
- error. For ``DecodeFSDefault ``, the return type is ``const char * ``; return a ``NULL ``
1073
- pointer to indicate an error.
1087
+ None of these take parameters.
1088
+ For all of these, return ``-1 `` to indicate error.
1074
1089
1075
1090
(There's also an experimental ``NoneType `` converter, which lets you
1076
1091
return ``Py_None `` on success or ``NULL `` on failure, without having
0 commit comments