Skip to content

Commit f8890e5

Browse files
serhiy-storchakaerlend-aasland
authored andcommitted
Improve highlighting of some code blocks. (python/cpython#6401)
1 parent 355e339 commit f8890e5

1 file changed

Lines changed: 51 additions & 17 deletions

File tree

Doc/howto/clinic.rst

Lines changed: 51 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -267,12 +267,16 @@ Let's dive in!
267267
should get its own line. All the parameter lines should be
268268
indented from the function name and the docstring.
269269

270-
The general form of these parameter lines is as follows::
270+
The general form of these parameter lines is as follows:
271+
272+
.. code-block:: none
271273
272274
name_of_parameter: converter
273275
274276
If the parameter has a default value, add that after the
275-
converter::
277+
converter:
278+
279+
.. code-block:: none
276280
277281
name_of_parameter: converter = default_value
278282
@@ -925,13 +929,17 @@ Parameter default values
925929
------------------------
926930

927931
Default values for parameters can be any of a number of values.
928-
At their simplest, they can be string, int, or float literals::
932+
At their simplest, they can be string, int, or float literals:
933+
934+
.. code-block:: none
929935
930936
foo: str = "abc"
931937
bar: int = 123
932938
bat: float = 45.6
933939
934-
They can also use any of Python's built-in constants::
940+
They can also use any of Python's built-in constants:
941+
942+
.. code-block:: none
935943
936944
yep: bool = True
937945
nope: bool = False
@@ -959,7 +967,9 @@ It can be an entire expression, using math operators and looking up attributes
959967
on objects. However, this support isn't exactly simple, because of some
960968
non-obvious semantics.
961969

962-
Consider the following example::
970+
Consider the following example:
971+
972+
.. code-block:: none
963973
964974
foo: Py_ssize_t = sys.maxsize - 1
965975
@@ -970,7 +980,9 @@ runtime, when the user asks for the function's signature.
970980

971981
What namespace is available when the expression is evaluated? It's evaluated
972982
in the context of the module the builtin came from. So, if your module has an
973-
attribute called "``max_widgets``", you may simply use it::
983+
attribute called "``max_widgets``", you may simply use it:
984+
985+
.. code-block:: none
974986
975987
foo: Py_ssize_t = max_widgets
976988
@@ -982,7 +994,9 @@ it's best to restrict yourself to modules that are preloaded by Python itself.)
982994
Evaluating default values only at runtime means Argument Clinic can't compute
983995
the correct equivalent C default value. So you need to tell it explicitly.
984996
When you use an expression, you must also specify the equivalent expression
985-
in C, using the ``c_default`` parameter to the converter::
997+
in C, using the ``c_default`` parameter to the converter:
998+
999+
.. code-block:: none
9861000
9871001
foo: Py_ssize_t(c_default="PY_SSIZE_T_MAX - 1") = sys.maxsize - 1
9881002
@@ -1359,7 +1373,9 @@ Let's start with defining some terminology:
13591373
A field, in this context, is a subsection of Clinic's output.
13601374
For example, the ``#define`` for the ``PyMethodDef`` structure
13611375
is a field, called ``methoddef_define``. Clinic has seven
1362-
different fields it can output per function definition::
1376+
different fields it can output per function definition:
1377+
1378+
.. code-block:: none
13631379
13641380
docstring_prototype
13651381
docstring_definition
@@ -1416,7 +1432,9 @@ Let's start with defining some terminology:
14161432

14171433
Clinic defines five new directives that let you reconfigure its output.
14181434

1419-
The first new directive is ``dump``::
1435+
The first new directive is ``dump``:
1436+
1437+
.. code-block:: none
14201438
14211439
dump <destination>
14221440
@@ -1425,15 +1443,19 @@ the current block, and empties it. This only works with ``buffer`` and
14251443
``two-pass`` destinations.
14261444

14271445
The second new directive is ``output``. The most basic form of ``output``
1428-
is like this::
1446+
is like this:
1447+
1448+
.. code-block:: none
14291449
14301450
output <field> <destination>
14311451
14321452
This tells Clinic to output *field* to *destination*. ``output`` also
14331453
supports a special meta-destination, called ``everything``, which tells
14341454
Clinic to output *all* fields to that *destination*.
14351455

1436-
``output`` has a number of other functions::
1456+
``output`` has a number of other functions:
1457+
1458+
.. code-block:: none
14371459
14381460
output push
14391461
output pop
@@ -1508,15 +1530,19 @@ preset configurations, as follows:
15081530
Suppresses the ``impl_prototype``, write the ``docstring_definition``
15091531
and ``parser_definition`` to ``buffer``, write everything else to ``block``.
15101532

1511-
The third new directive is ``destination``::
1533+
The third new directive is ``destination``:
1534+
1535+
.. code-block:: none
15121536
15131537
destination <name> <command> [...]
15141538
15151539
This performs an operation on the destination named ``name``.
15161540

15171541
There are two defined subcommands: ``new`` and ``clear``.
15181542

1519-
The ``new`` subcommand works like this::
1543+
The ``new`` subcommand works like this:
1544+
1545+
.. code-block:: none
15201546
15211547
destination <name> new <type>
15221548
@@ -1564,15 +1590,19 @@ There are five destination types:
15641590
A two-pass buffer, like the "two-pass" builtin destination above.
15651591

15661592

1567-
The ``clear`` subcommand works like this::
1593+
The ``clear`` subcommand works like this:
1594+
1595+
.. code-block:: none
15681596
15691597
destination <name> clear
15701598
15711599
It removes all the accumulated text up to this point in the destination.
15721600
(I don't know what you'd need this for, but I thought maybe it'd be
15731601
useful while someone's experimenting.)
15741602

1575-
The fourth new directive is ``set``::
1603+
The fourth new directive is ``set``:
1604+
1605+
.. code-block:: none
15761606
15771607
set line_prefix "string"
15781608
set line_suffix "string"
@@ -1590,7 +1620,9 @@ Both of these support two format strings:
15901620
Turns into the string ``*/``, the end-comment text sequence for C files.
15911621

15921622
The final new directive is one you shouldn't need to use directly,
1593-
called ``preserve``::
1623+
called ``preserve``:
1624+
1625+
.. code-block:: none
15941626
15951627
preserve
15961628
@@ -1638,7 +1670,9 @@ like so::
16381670
#endif /* HAVE_FUNCTIONNAME */
16391671

16401672
Then, remove those three lines from the ``PyMethodDef`` structure,
1641-
replacing them with the macro Argument Clinic generated::
1673+
replacing them with the macro Argument Clinic generated:
1674+
1675+
.. code-block:: none
16421676
16431677
MODULE_FUNCTIONNAME_METHODDEF
16441678

0 commit comments

Comments
 (0)