]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] Docs: turn getopt examples into doctests (GH-126377) (#126385)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 4 Nov 2024 08:34:36 +0000 (09:34 +0100)
committerGitHub <noreply@github.com>
Mon, 4 Nov 2024 08:34:36 +0000 (08:34 +0000)
(cherry picked from commit 0d80777981f95bbc79b146fc78b2189c82521ab9)

Co-authored-by: Erlend E. Aasland <erlend@python.org>
Doc/library/getopt.rst

index d43d3250732306b4e89c6b0faf043627ddd75fb8..3ab44b9fc561087912d98f7a28e455250c06a27f 100644 (file)
@@ -97,6 +97,8 @@ exception:
 
 An example using only Unix style options:
 
+.. doctest::
+
    >>> import getopt
    >>> args = '-a -b -cfoo -d bar a1 a2'.split()
    >>> args
@@ -109,6 +111,8 @@ An example using only Unix style options:
 
 Using long option names is equally easy:
 
+.. doctest::
+
    >>> s = '--condition=foo --testing --output-file abc.def -x a1 a2'
    >>> args = s.split()
    >>> args
@@ -120,7 +124,9 @@ Using long option names is equally easy:
    >>> args
    ['a1', 'a2']
 
-In a script, typical usage is something like this::
+In a script, typical usage is something like this:
+
+.. testcode::
 
    import getopt, sys
 
@@ -150,7 +156,9 @@ In a script, typical usage is something like this::
        main()
 
 Note that an equivalent command line interface could be produced with less code
-and more informative help and error messages by using the :mod:`argparse` module::
+and more informative help and error messages by using the :mod:`argparse` module:
+
+.. testcode::
 
    import argparse