@@ -1033,19 +1033,36 @@ you're not permitted to use:
1033
1033
Using a return converter
1034
1034
------------------------
1035
1035
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 * `
1038
1040
at the last moment. Argument Clinic handles converting your inputs from Python types
1039
1041
into native C types—why not have it convert your return value from a native C type
1040
1042
into a Python type too?
1041
1043
1042
1044
That's what a "return converter" does. It changes your impl function to return
1043
1045
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 * `.
1045
1047
1046
1048
The syntax for return converters is similar to that of parameter converters.
1047
1049
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;
1049
1066
they take arguments, the arguments are all keyword-only, and if you're not changing
1050
1067
any of the default arguments you can omit the parentheses.
1051
1068
@@ -1066,19 +1083,17 @@ Currently Argument Clinic supports only a few return converters:
1066
1083
.. code-block :: none
1067
1084
1068
1085
bool
1086
+ double
1087
+ float
1069
1088
int
1070
- unsigned int
1071
1089
long
1072
- unsigned int
1073
- size_t
1074
1090
Py_ssize_t
1075
- float
1076
- double
1077
- DecodeFSDefault
1091
+ size_t
1092
+ unsigned int
1093
+ unsigned long
1078
1094
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.
1082
1097
1083
1098
To see all the return converters Argument Clinic supports, along with
1084
1099
their parameters (if any),
0 commit comments