You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[3.12] Docs: Argument Clinic: Move the CConverter class to the reference (GH-107671) (#107701)
Docs: Argument Clinic: Move the CConverter class to the reference (GH-107671)
(cherry picked from commit a6675b1)
Co-authored-by: Erlend E. Aasland <erlend@python.org>
Copy file name to clipboard<
10000
span class="prc-TooltipV2-Tooltip-cYMVY" data-direction="s" role="tooltip" aria-hidden="true" id=":R8rtlab:">Expand all lines: Doc/howto/clinic.rst
+69-64Lines changed: 69 additions & 64 deletions
Original file line number
Diff line number
Diff line change
@@ -193,6 +193,71 @@ The CLI supports the following options:
193
193
The list of files to process.
194
194
195
195
196
+
.. _clinic-classes:
197
+
198
+
Classes for extending Argument Clinic
199
+
-------------------------------------
200
+
201
+
.. module:: clinic
202
+
203
+
.. class:: CConverter
204
+
205
+
The base class for all converters.
206
+
See :ref:`clinic-howto-custom-converter` for how to subclass this class.
207
+
208
+
.. attribute:: type
209
+
210
+
The C type to use for this variable.
211
+
:attr:`!type` should be a Python string specifying the type,
212
+
e.g. ``'int'``.
213
+
If this is a pointer type, the type string should end with ``' *'``.
214
+
215
+
.. attribute:: default
216
+
217
+
The Python default value for this parameter, as a Python value.
218
+
Or the magic value ``unspecified`` if there is no default.
219
+
220
+
.. attribute:: py_default
221
+
222
+
:attr:`!default` as it should appear in Python code,
223
+
as a string.
224
+
Or ``None`` if there is no default.
225
+
226
+
.. attribute:: c_default
227
+
228
+
:attr:`!default` as it should appear in C code,
229
+
as a string.
230
+
Or ``None`` if there is no default.
231
+
232
+
.. attribute:: c_ignored_default
233
+
234
+
The default value used to initialize the C variable when
235
+
there is no default, but not specifying a default may
236
+
result in an "uninitialized variable" warning. This can
237
+
easily happen when using option groups—although
238
+
properly written code will never actually use this value,
239
+
the variable does get passed in to the impl, and the
240
+
C compiler will complain about the "use" of the
241
+
uninitialized value. This value should always be a
242
+
non-empty string.
243
+
244
+
.. attribute:: converter
245
+
246
+
The name of the C converter function, as a string.
247
+
248
+
.. attribute:: impl_by_reference
249
+
250
+
A boolean value. If true,
251
+
Argument Clinic will add a ``&`` in front of the name of
252
+
the variable when passing it into the impl function.
253
+
254
+
.. attribute:: parse_by_reference
255
+
256
+
A boolean value. If true,
257
+
Argument Clinic will add a ``&`` in front of the name of
258
+
the variable when passing it into :c:func:`PyArg_ParseTuple`.
259
+
260
+
196
261
.. _clinic-tutorial:
197
262
198
263
Tutorial
@@ -1348,7 +1413,7 @@ See also :pep:`573`.
1348
1413
How to write a custom converter
1349
1414
-------------------------------
1350
1415
1351
-
A converter is a Python class that inherits from :py:class:`!CConverter`.
1416
+
A converter is a Python class that inherits from :py:class:`CConverter`.
1352
1417
The main purpose of a custom converter, is for parameters parsed with
1353
1418
the ``O&`` format unit --- parsing such a parameter means calling
1354
1419
a :c:func:`PyArg_ParseTuple` "converter function".
@@ -1360,73 +1425,13 @@ your converter class with the ``_converter`` suffix stripped off.
1360
1425
1361
1426
Instead of subclassing :py:meth:`!CConverter.__init__`,
1362
1427
write a :py:meth:`!converter_init` method.
1363
-
Apart for the *self* parameter, all additional :py:meth:`!converter_init`
1364
-
parameters **must** be keyword-only.
1428
+
:py:meth:`!converter_init` always accepts a *self* parameter.
1429
+
After *self*, all additional parameters **must** be keyword-only.
1365
1430
Any arguments passed to the converter in Argument Clinic
1366
1431
will be passed along to your :py:meth:`!converter_init` method.
1367
-
See :py:class:`!CConverter` for a list of members you may wish to specify in
1432
+
See :py:class:`CConverter` for a list of members you may wish to specify in
1368
1433
your subclass.
1369
1434
1370
-
.. module:: clinic
1371
-
1372
-
.. class:: CConverter
1373
-
1374
-
The base class for all converters.
1375
-
See :ref:`clinic-howto-custom-converter` for how to subclass this class.
1376
-
1377
-
.. attribute:: type
1378
-
1379
-
The C type to use for this variable.
1380
-
:attr:`!type` should be a Python string specifying the type,
1381
-
e.g. ``'int'``.
1382
-
If this is a pointer type, the type string should end with ``' *'``.
1383
-
1384
-
.. attribute:: default
1385
-
1386
-
The Python default value for this parameter, as a Python value.
1387
-
Or the magic value ``unspecified`` if there is no default.
1388
-
1389
-
.. attribute:: py_default
1390
-
1391
-
:attr:`!default` as it should appear in Python code,
1392
-
as a string.
1393
-
Or ``None`` if there is no default.
1394
-
1395
-
.. attribute:: c_default
1396
-
1397
-
:attr:`!default` as it should appear in C code,
1398
-
as a string.
1399
-
Or ``None`` if there is no default.
1400
-
1401
-
.. attribute:: c_ignored_default
1402
-
1403
-
The default value used to initialize the C variable when
1404
-
there is no default, but not specifying a default may
1405
-
result in an "uninitialized variable" warning. This can
1406
-
easily happen when using option groups—although
1407
-
properly written code will never actually use this value,
1408
-
the variable does get passed in to the impl, and the
1409
-
C compiler will complain about the "use" of the
1410
-
uninitialized value. This value should always be a
1411
-
non-empty string.
1412
-
1413
-
.. attribute:: converter
1414
-
1415
-
The name of the C converter function, as a string.
1416
-
1417
-
.. attribute:: impl_by_reference
1418
-
1419
-
A boolean value. If true,
1420
-
Argument Clinic will add a ``&`` in front of the name of
1421
-
the variable when passing it into the impl function.
1422
-
1423
-
.. attribute:: parse_by_reference
1424
-
1425
-
A boolean value. If true,
1426
-
Argument Clinic will add a ``&`` in front of the name of
1427
-
the variable when passing it into :c:func:`PyArg_ParseTuple`.
1428
-
1429
-
1430
1435
Here's the simplest example of a custom converter, from :source:`Modules/zlibmodule.c`::
0 commit comments