@@ -552,15 +552,12 @@ Let's dive in!
552552 Congratulations, you've ported your first function to work with Argument Clinic!
553553
554554
555- Advanced topics
556- ===============
555+ How-to guides
556+ =============
557557
558- Now that you've had some experience working with Argument Clinic, it's time
559- for some advanced topics.
560558
561-
562- Symbolic default values
563- -----------------------
559+ How to use symbolic default values
560+ ----------------------------------
564561
565562The default value you provide for a parameter can't be any arbitrary
566563expression. Currently the following are explicitly supported:
@@ -575,8 +572,8 @@ expression. Currently the following are explicitly supported:
575572to allow full expressions like ``CONSTANT - 1 ``.)
576573
577574
578- Renaming the C functions and variables generated by Argument Clinic
579- -------------------------------------------------------------------
575+ How to to rename C functions and variables generated by Argument Clinic
576+ -----------------------------------------------------------------------
580577
581578Argument Clinic automatically names the functions it generates for you.
582579Occasionally this may cause a problem, if the generated name collides with
@@ -618,8 +615,8 @@ array) would be ``file``, but the C variable would be named ``file_obj``.
618615You can use this to rename the ``self `` parameter too!
619616
620617
621- Converting functions using PyArg_UnpackTuple
622- --------------------------------------------
618+ How to convert functions using `` PyArg_UnpackTuple ``
619+ ----------------------------------------------------
623620
624621To convert a function parsing its arguments with :c:func: `PyArg_UnpackTuple `,
625622simply write out all the arguments, specifying each as an ``object ``. You
@@ -631,8 +628,8 @@ Currently the generated code will use :c:func:`PyArg_ParseTuple`, but this
631628will change soon.
632629
633630
634- Optional groups
635- ---------------
631+ How to use optional groups
632+ --------------------------
636633
637634Some legacy functions have a tricky approach to parsing their arguments:
638635they count the number of positional arguments, then use a ``switch `` statement
@@ -724,8 +721,8 @@ Notes:
724721 use optional groups for new code.
725722
726723
727- Using real Argument Clinic converters, instead of "legacy converters"
728- ---------------------------------------------------------------------
724+ How to use real Argument Clinic converters, instead of "legacy converters"
725+ --------------------------------------------------------------------------
729726
730727To save time, and to minimize how much you need to learn
731728to achieve your first port to Argument Clinic, the walkthrough above tells
@@ -892,17 +889,17 @@ it accepts, along with the default value for each parameter.
892889Just run ``Tools/clinic/clinic.py --converters `` to see the full list.
893890
894891
895- Py_buffer
896- ---------
892+ How to use the `` Py_buffer `` converter
893+ --------------------------------------
897894
898895When using the ``Py_buffer `` converter
899896(or the ``'s*' ``, ``'w*' ``, ``'*y' ``, or ``'z*' `` legacy converters),
900897you *must * not call :c:func: `PyBuffer_Release ` on the provided buffer.
901898Argument Clinic generates code that does it for you (in the parsing function).
902899
903900
904- Advanced converters
905- -------------------
901+ How to use advanced converters
902+ ------------------------------
906903
907904Remember those format units you skipped for your first
908905time because they were advanced? Here's how to handle those too.
@@ -933,8 +930,8 @@ hard-coded encoding strings for parameters whose format units start with ``e``.
933930
934931.. _default_values :
935932
936- Parameter default values
937- ------------------------
933+ How to assign default values to parameter
934+ -----------------------------------------
938935
939936Default values for parameters can be any of a number of values.
940937At their simplest, they can be string, int, or float literals:
@@ -957,8 +954,8 @@ There's also special support for a default value of ``NULL``, and
957954for simple expressions, documented in the following sections.
958955
959956
960- The ``NULL `` default value
961- --------------------------
957+ How to use the ``NULL `` default value
958+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
962959
963960For string and object parameters, you can set them to ``None `` to indicate
964961that there's no default. However, that means the C variable will be
@@ -968,8 +965,8 @@ behaves like a default value of ``None``, but the C variable is initialized
968965with ``NULL ``.
969966
970967
971- Expressions specified as default values
972- ---------------------------------------
968+ How to use expressions as default values
969+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
973970
974971The default value for a parameter can be more than just a literal value.
975972It can be an entire expression, using math operators and looking up attributes
@@ -1025,8 +1022,8 @@ you're not permitted to use:
10251022* Tuple/list/set/dict literals.
10261023
10271024
1028- Using a return converter
1029- ------------------------
1025+ How to use return converters
1026+ ----------------------------
10301027
10311028By default, the impl function Argument Clinic generates for you returns
10321029:c:type: `PyObject * <PyObject> `.
@@ -1100,8 +1097,8 @@ their parameters (if any),
11001097just run ``Tools/clinic/clinic.py --converters `` for the full list.
11011098
11021099
1103- Cloning existing functions
1104- --------------------------
1100+ How to clone existing functions
1101+ -------------------------------
11051102
11061103If you have a number of functions that look similar, you may be able to
11071104use Clinic's "clone" feature. When you clone an existing function,
@@ -1144,8 +1141,8 @@ Also, the function you are cloning from must have been previously defined
11441141in the current file.
11451142
11461143
1147- Calling Python code
1148- -------------------
1144+ How to call Python code
1145+ -----------------------
11491146
11501147The rest of the advanced topics require you to write Python code
11511148which lives inside your C file and modifies Argument Clinic's
@@ -1172,8 +1169,8 @@ variable to the C code::
11721169 /*[python checksum:...]*/
11731170
11741171
1175- Using a "self converter"
1176- ------------------------
1172+ How to use the "self converter"
1173+ -------------------------------
11771174
11781175Argument Clinic automatically adds a "self" parameter for you
11791176using a default converter. It automatically sets the ``type ``
@@ -1224,8 +1221,8 @@ type for ``self``, it's best to create your own converter, subclassing
12241221 [clinic start generated code]*/
12251222
12261223
1227- Using a "defining class" converter
1228- ----------------------------------
1224+ How to use the "defining class" converter
1225+ -----------------------------------------
12291226
12301227Argument Clinic facilitates gaining access to the defining class of a method.
12311228This is useful for :ref: `heap type <heap-types >` methods that need to fetch
@@ -1287,8 +1284,8 @@ state. Example from the ``setattro`` slot method in
12871284See also :pep: `573 `.
12881285
12891286
1290- Writing a custom converter
1291- --------------------------
1287+ How to write a custom converter
1288+ -------------------------------
12921289
12931290As we hinted at in the previous section... you can write your own converters!
12941291A converter is simply a Python class that inherits from ``CConverter ``.
@@ -1379,8 +1376,8 @@ You can see more examples of custom converters in the CPython
13791376source tree; grep the C files for the string ``CConverter ``.
13801377
13811378
1382- Writing a custom return converter
1383- ---------------------------------
1379+ How to write a custom return converter
1380+ --------------------------------------
13841381
13851382Writing a custom return converter is much like writing
13861383a custom converter. Except it's somewhat simpler, because return
@@ -1394,8 +1391,8 @@ specifically the implementation of ``CReturnConverter`` and
13941391all its subclasses.
13951392
13961393
1397- METH_O and METH_NOARGS
1398- ----------------------
1394+ How to convert `` METH_O `` and `` METH_NOARGS `` functions
1395+ -------------------------------------------------------
13991396
14001397To convert a function using ``METH_O ``, make sure the function's
14011398single argument is using the ``object `` converter, and mark the
@@ -1416,8 +1413,8 @@ You can still use a self converter, a return converter, and specify
14161413a ``type `` argument to the object converter for ``METH_O ``.
14171414
14181415
1419- tp_new and tp_init functions
1420- ----------------------------
1416+ How to convert `` tp_new `` and `` tp_init `` functions
1417+ ---------------------------------------------------
14211418
14221419You can convert ``tp_new `` and ``tp_init `` functions. Just name
14231420them ``__new__ `` or ``__init__ `` as appropriate. Notes:
@@ -1439,8 +1436,8 @@ them ``__new__`` or ``__init__`` as appropriate. Notes:
14391436 generated will throw an exception if it receives any.)
14401437
14411438
1442- Changing and redirecting Clinic's output
1443- ----------------------------------------
1439+ How to change and redirect Clinic's output
1440+ ------------------------------------------
14441441
14451442It can be inconvenient to have Clinic's output interspersed with
14461443your conventional hand-edited C code. Luckily, Clinic is configurable:
@@ -1722,8 +1719,8 @@ it in a Clinic block lets Clinic use its existing checksum functionality to ensu
17221719the file was not modified by hand before it gets overwritten.
17231720
17241721
1725- The #ifdef trick
1726- ----------------
1722+ How to use the `` #ifdef `` trick
1723+ -------------------------------
17271724
17281725If you're converting a function that isn't available on all platforms,
17291726there's a trick you can use to make life a little easier. The existing
@@ -1803,8 +1800,8 @@ Argument Clinic added to your file (it'll be at the very bottom), then
18031800move it above the ``PyMethodDef `` structure where that macro is used.
18041801
18051802
1806- Using Argument Clinic in Python files
1807- -------------------------------------
1803+ How to use Argument Clinic in Python files
1804+ ------------------------------------------
18081805
18091806It's actually possible to use Argument Clinic to preprocess Python files.
18101807There's no point to using Argument Clinic blocks, of course, as the output
0 commit comments