Skip to content

bpo-42843: Keep Sphinx 1.8 and Sphinx 2 compatibility #24282

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 25, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Revert "bpo-36675: Doc: Reveal doctest directives (GH-23620)"
This reverts commit c8a10d2.
  • Loading branch information
JulienPalard committed Jan 21, 2021
commit 882b94260cba6629a5b5e749a022b8e622e76ea5
4 changes: 2 additions & 2 deletions .azure-pipelines/docs-steps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ steps:
inputs:
versionSpec: '>=3.6'

- script: python -m pip install sphinx==3.2.1 blurb python-docs-theme
- script: python -m pip install sphinx==2.2.0 blurb python-docs-theme
displayName: 'Install build dependencies'

- ${{ if ne(parameters.latex, 'true') }}:
Expand All @@ -31,7 +31,7 @@ steps:
- ${{ if eq(parameters.upload, 'true') }}:
- task: PublishBuildArtifacts@1
displayName: 'Publish docs'

inputs:
PathToPublish: '$(build.sourcesDirectory)/Doc/build'
ArtifactName: docs
Expand Down
54 changes: 17 additions & 37 deletions Doc/library/doctest.rst
Original file line number Diff line number Diff line change
Expand Up @@ -719,51 +719,36 @@ above.
An example's doctest directives modify doctest's behavior for that single
example. Use ``+`` to enable the named behavior, or ``-`` to disable it.

For example, this test passes:
For example, this test passes::

.. doctest::
:no-trim-doctest-flags:

>>> print(list(range(20))) # doctest: +NORMALIZE_WHITESPACE
>>> print(list(range(20))) # doctest: +NORMALIZE_WHITESPACE
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
10, 11, 12, 13, 14, 15, 16, 17, 18, 19]

Without the directive it would fail, both because the actual output doesn't have
two blanks before the single-digit list elements, and because the actual output
is on a single line. This test also passes, and also requires a directive to do
so:

.. doctest::
:no-trim-doctest-flags:
so::

>>> print(list(range(20))) # doctest: +ELLIPSIS
>>> print(list(range(20))) # doctest: +ELLIPSIS
[0, 1, ..., 18, 19]

Multiple directives can be used on a single physical line, separated by
commas:
commas::

.. doctest::
:no-trim-doctest-flags:

>>> print(list(range(20))) # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE
>>> print(list(range(20))) # doctest: +ELLIPSIS, +NORMALIZE_WHITESPACE
[0, 1, ..., 18, 19]

If multiple directive comments are used for a single example, then they are
combined:

.. doctest::
:no-trim-doctest-flags:
combined::

>>> print(list(range(20))) # doctest: +ELLIPSIS
... # doctest: +NORMALIZE_WHITESPACE
>>> print(list(range(20))) # doctest: +ELLIPSIS
... # doctest: +NORMALIZE_WHITESPACE
[0, 1, ..., 18, 19]

As the previous example shows, you can add ``...`` lines to your example
containing only directives. This can be useful when an example is too long for
a directive to comfortably fit on the same line:

.. doctest::
:no-trim-doctest-flags:
a directive to comfortably fit on the same line::

>>> print(list(range(5)) + list(range(10, 20)) + list(range(30, 40)))
... # doctest: +ELLIPSIS
Expand Down Expand Up @@ -808,23 +793,18 @@ instead. Another is to do ::

There are others, but you get the idea.

Another bad idea is to print things that embed an object address, like

.. doctest::
Another bad idea is to print things that embed an object address, like ::

>>> id(1.0) # certain to fail some of the time # doctest: +SKIP
>>> id(1.0) # certain to fail some of the time
7948648
>>> class C: pass
>>> C() # the default repr() for instances embeds an address # doctest: +SKIP
<C object at 0x00AC18F0>

The :const:`ELLIPSIS` directive gives a nice approach for the last example:
>>> C() # the default repr() for instances embeds an address
<__main__.C instance at 0x00AC18F0>

.. doctest::
:no-trim-doctest-flags:
The :const:`ELLIPSIS` directive gives a nice approach for the last example::

>>> C() # doctest: +ELLIPSIS
<C object at 0x...>
>>> C() #doctest: +ELLIPSIS
<__main__.C instance at 0x...>

Floating-point numbers are also subject to small output variations across
platforms, because Python defers to the platform C library for float formatting,
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy