Skip to content

Commit 0b26ccf

Browse files
committed
Issue #12947: Better workaround for the problem with doctest directives being stripped from code examples that are intended to illustrate those directives
1 parent 8f80e0a commit 0b26ccf

1 file changed

Lines changed: 20 additions & 10 deletions

File tree

Doc/library/doctest.rst

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -651,14 +651,15 @@ An example's doctest directives modify doctest's behavior for that single
651651
example. Use ``+`` to enable the named behavior, or ``-`` to disable it.
652652

653653
.. note::
654-
Due to an `unfortunate bug`_ in our documentation publishing process, the
655-
directives in the following examples are not being displayed in the
656-
rendered HTML version. Please use the "Show Source" link in the sidebar
657-
to view the details of the directive usage examples.
654+
Due to an `unfortunate limitation`_ of our current documentation
655+
publishing process, syntax highlighting has been disabled in the examples
656+
below in order to ensure the doctest directives are correctly displayed.
658657

659-
.. _unfortunate bug: http://bugs.python.org/issue12947
658+
.. _unfortunate limitation: http://bugs.python.org/issue12947
660659

661-
For example, this test passes::
660+
For example, this test passes:
661+
662+
.. code-block:: text
662663
663664
>>> print(list(range(20))) #doctest: +NORMALIZE_WHITESPACE
664665
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
@@ -667,26 +668,35 @@ For example, this test passes::
667668
Without the directive it would fail, both because the actual output doesn't have
668669
two blanks before the single-digit list elements, and because the actual output
669670
is on a single line. This test also passes, and also requires a directive to do
670-
so::
671+
so:
672+
673+
.. code-block:: text
671674
672675
>>> print(list(range(20))) # doctest: +ELLIPSIS
673676
[0, 1, ..., 18, 19]
674677
675-
Multiple directives can be used on a single physical line, separated by commas::
678+
Multiple directives can be used on a single physical line, separated by
679+
commas:
680+
681+
.. code-block:: text
676682
677683
>>> print(list(range(20))) # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE
678684
[0, 1, ..., 18, 19]
679685
680686
If multiple directive comments are used for a single example, then they are
681-
combined::
687+
combined:
688+
689+
.. code-block:: text
682690
683691
>>> print(list(range(20))) # doctest: +ELLIPSIS
684692
... # doctest: +NORMALIZE_WHITESPACE
685693
[0, 1, ..., 18, 19]
686694
687695
As the previous example shows, you can add ``...`` lines to your example
688696
containing only directives. This can be useful when an example is too long for
689-
a directive to comfortably fit on the same line::
697+
a directive to comfortably fit on the same line:
698+
699+
.. code-block:: text
690700
691701
>>> print(list(range(5)) + list(range(10, 20)) + list(range(30, 40)))
692702
... # doctest: +ELLIPSIS

0 commit comments

Comments
 (0)