]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-142389: Add backticks to stdlib argparse help to display in colour (#149384)
authorHugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Mon, 4 May 2026 22:23:18 +0000 (01:23 +0300)
committerGitHub <noreply@github.com>
Mon, 4 May 2026 22:23:18 +0000 (22:23 +0000)
Co-authored-by: Savannah Ostrowski <savannah@python.org>
33 files changed:
Lib/ast.py
Lib/asyncio/__main__.py
Lib/calendar.py
Lib/code.py
Lib/compileall.py
Lib/dis.py
Lib/doctest.py
Lib/ensurepip/__init__.py
Lib/gzip.py
Lib/http/server.py
Lib/inspect.py
Lib/json/tool.py
Lib/mimetypes.py
Lib/pdb.py
Lib/pickle.py
Lib/pickletools.py
Lib/platform.py
Lib/profiling/sampling/cli.py
Lib/py_compile.py
Lib/random.py
Lib/sqlite3/__main__.py
Lib/tarfile.py
Lib/test/libregrtest/cmdline.py
Lib/timeit.py
Lib/tokenize.py
Lib/trace.py
Lib/unittest/main.py
Lib/uuid.py
Lib/venv/__init__.py
Lib/webbrowser.py
Lib/zipapp.py
Lib/zipfile/__init__.py
Misc/NEWS.d/next/Library/2026-05-05-00-30-04.gh-issue-142389.4daLzc.rst [new file with mode: 0644]

index a7997c4b7406355d9abcff5bb39fe06edd078015..4f88a554344cc95b18e391c1a1287937d4c9a148 100644 (file)
@@ -666,7 +666,7 @@ def main(args=None):
 
     parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
     parser.add_argument('infile', nargs='?', default='-',
-                        help='the file to parse; defaults to stdin')
+                        help='the file to parse; defaults to `stdin`')
     parser.add_argument('-m', '--mode', default='exec',
                         choices=('exec', 'single', 'eval', 'func_type'),
                         help='specify what kind of code must be parsed')
@@ -679,8 +679,8 @@ def main(args=None):
                         help='indentation of nodes (number of spaces)')
     parser.add_argument('--feature-version',
                         type=str, default=None, metavar='VERSION',
-                        help='Python version in the format 3.x '
-                             '(for example, 3.10)')
+                        help='Python version in the format `3.x` '
+                             '(for example, `3.10`)')
     parser.add_argument('-O', '--optimize',
                         type=int, default=-1, metavar='LEVEL',
                         help='optimization level for parser')
index 37eba9657ac5a884e0c16e55ab55c61d5cf8a4f2..7f0565d0b8ddc765b9c864f89fcd5e67bf1576ba 100644 (file)
@@ -159,7 +159,6 @@ if __name__ == '__main__':
     parser = argparse.ArgumentParser(
         prog="python3 -m asyncio",
         description="Interactive asyncio shell and CLI tools",
-        color=True,
     )
     subparsers = parser.add_subparsers(help="sub-commands", dest="command")
     ps = subparsers.add_parser(
index fa9775ab040b14935cd1d2608c2b9fc6b4a6d223..92fe6b7723fe268e7b0e2e31f897005239a65d2b 100644 (file)
@@ -922,7 +922,7 @@ def main(args=None):
         "-t", "--type",
         default="text",
         choices=("text", "html"),
-        help="output type (text or html)"
+        help="output type (`text` or `html`)"
     )
     parser.add_argument(
         "-f", "--first-weekday",
index f7e275d8801b7c3de0c43b6576661e583a6c2263..df1d7199e3393414fd9310f759e0e023a896c91f 100644 (file)
@@ -385,7 +385,7 @@ def interact(banner=None, readfunc=None, local=None, exitmsg=None, local_exit=Fa
 if __name__ == "__main__":
     import argparse
 
-    parser = argparse.ArgumentParser(color=True)
+    parser = argparse.ArgumentParser()
     parser.add_argument('-q', action='store_true',
                        help="don't print version and copyright messages")
     args = parser.parse_args()
index c452aed135838f959e7c4d0d592d8b51bfa16734..812a496611e043f5761725b223e42aff49e98711 100644 (file)
@@ -326,7 +326,6 @@ def main():
 
     parser = argparse.ArgumentParser(
         description='Utilities to support installing Python libraries.',
-        color=True,
     )
     parser.add_argument('-l', action='store_const', const=0,
                         default=None, dest='maxlevels',
@@ -338,10 +337,10 @@ def main():
     parser.add_argument('-f', action='store_true', dest='force',
                         help='force rebuild even if timestamps are up to date')
     parser.add_argument('-q', action='count', dest='quiet', default=0,
-                        help='output only error messages; -qq will suppress '
+                        help='output only error messages; `-qq` will suppress '
                              'the error messages as well.')
     parser.add_argument('-b', action='store_true', dest='legacy',
-                        help='use legacy (pre-PEP3147) compiled file locations')
+                        help='use legacy (pre-PEP 3147) compiled file locations')
     parser.add_argument('-d', metavar='DESTDIR',  dest='ddir', default=None,
                         help=('directory to prepend to file paths for use in '
                               'compile-time tracebacks and in runtime '
@@ -367,28 +366,28 @@ def main():
                               'of each file considered for compilation'))
     parser.add_argument('-i', metavar='FILE', dest='flist',
                         help=('add all the files and directories listed in '
-                              'FILE to the list considered for compilation; '
-                              'if "-", names are read from stdin'))
+                              '`FILE` to the list considered for compilation; '
+                              'if `"-"`, names are read from `stdin`'))
     parser.add_argument('compile_dest', metavar='FILE|DIR', nargs='*',
                         help=('zero or more file and directory names '
                               'to compile; if no arguments given, defaults '
-                              'to the equivalent of -l sys.path'))
+                              'to the equivalent of `-l` `sys.path`'))
     parser.add_argument('-j', '--workers', default=1,
                         type=int, help='Run compileall concurrently')
     invalidation_modes = [mode.name.lower().replace('_', '-')
                           for mode in py_compile.PycInvalidationMode]
     parser.add_argument('--invalidation-mode',
                         choices=sorted(invalidation_modes),
-                        help=('set .pyc invalidation mode; defaults to '
-                              '"checked-hash" if the SOURCE_DATE_EPOCH '
+                        help=('set `.pyc` invalidation mode; defaults to '
+                              '`"checked-hash"` if the `SOURCE_DATE_EPOCH` '
                               'environment variable is set, and '
-                              '"timestamp" otherwise.'))
+                              '`"timestamp"` otherwise.'))
     parser.add_argument('-o', action='append', type=int, dest='opt_levels',
                         help=('Optimization levels to run compilation with. '
-                              'Default is -1 which uses the optimization level '
-                              'of the Python interpreter itself (see -O).'))
+                              'Default is `-1` which uses the optimization level '
+                              'of the Python interpreter itself (see `-O`).'))
     parser.add_argument('-e', metavar='DIR', dest='limit_sl_dest',
-                        help='Ignore symlinks pointing outsite of the DIR')
+                        help='Ignore symlinks pointing outsite of the `DIR`')
     parser.add_argument('--hardlink-dupes', action='store_true',
                         dest='hardlink_dupes',
                         help='Hardlink duplicated pyc files')
index 64f3450da3071b801b78a0c64ab06b91821f777c..d60507ae47345330d0aeedc24c22e57339d73606 100644 (file)
@@ -1146,7 +1146,7 @@ class Bytecode:
 def main(args=None):
     import argparse
 
-    parser = argparse.ArgumentParser(color=True)
+    parser = argparse.ArgumentParser()
     parser.add_argument('-C', '--show-caches', action='store_true',
                         help='show inline caches')
     parser.add_argument('-O', '--show-offsets', action='store_true',
index 0fcfa1e3e9714467b0a399044154b29d2c74947d..05acac1745ace9432c91a17395a0acef9ca03e75 100644 (file)
@@ -2951,7 +2951,7 @@ __test__ = {"_TestClass": _TestClass,
 def _test():
     import argparse
 
-    parser = argparse.ArgumentParser(description="doctest runner", color=True)
+    parser = argparse.ArgumentParser(description="doctest runner")
     parser.add_argument('-v', '--verbose', action='store_true', default=False,
                         help='print very verbose output for all tests')
     parser.add_argument('-o', '--option', action='append',
@@ -2961,8 +2961,8 @@ def _test():
                               ' than once to apply multiple options'))
     parser.add_argument('-f', '--fail-fast', action='store_true',
                         help=('stop running tests after first failure (this'
-                              ' is a shorthand for -o FAIL_FAST, and is'
-                              ' in addition to any other -o options)'))
+                              ' is a shorthand for `-o FAIL_FAST`, and is'
+                              ' in addition to any other `-o` options)'))
     parser.add_argument('file', nargs='+',
                         help='file containing the tests to run')
     args = parser.parse_args()
index 9077e84e958ccea92d9eb9927f4cd3c22e448d4b..ab6b95e0ba60c09737006632b404c9e2412796e7 100644 (file)
@@ -217,7 +217,7 @@ def _uninstall_helper(*, verbosity=0):
 
 def _main(argv=None):
     import argparse
-    parser = argparse.ArgumentParser(color=True)
+    parser = argparse.ArgumentParser()
     parser.add_argument(
         "--version",
         action="version",
index 8a2faf846bf8941826a064cb83f3b813cdcfe273..971063aa24f8712c6a68770fa28f9da68f204499 100644 (file)
@@ -664,15 +664,14 @@ def decompress(data):
 def main():
     from argparse import ArgumentParser
     parser = ArgumentParser(description=
-        "A simple command line interface for the gzip module: act like gzip, "
+        "A simple command line interface for the `gzip` module: act like `gzip`, "
         "but do not delete the input file.",
-        color=True,
     )
     group = parser.add_mutually_exclusive_group()
     group.add_argument('--fast', action='store_true', help='compress faster')
     group.add_argument('--best', action='store_true', help='compress better')
     group.add_argument("-d", "--decompress", action="store_true",
-                        help="act like gunzip instead of gzip")
+                        help="act like `gunzip` instead of `gzip`")
 
     parser.add_argument("args", nargs="*", default=["-"], metavar='file')
     args = parser.parse_args()
index 16ea7f3f93693f7b80362d9b16ed1f48e88a3e91..ebc85052aecb9006e4e597a6d5d9b77d5a742463 100644 (file)
@@ -1081,7 +1081,7 @@ def _main(args=None):
     import argparse
     import contextlib
 
-    parser = argparse.ArgumentParser(color=True)
+    parser = argparse.ArgumentParser()
     parser.add_argument('-b', '--bind', metavar='ADDRESS',
                         help='bind to this address '
                              '(default: all interfaces)')
index af304f186a69bc2c12fdf1111e143819c28f752d..9eb87b0d277918933e8dbe966624c487a9485de3 100644 (file)
@@ -3445,11 +3445,11 @@ def _main():
     import argparse
     import importlib
 
-    parser = argparse.ArgumentParser(color=True)
+    parser = argparse.ArgumentParser()
     parser.add_argument(
         'object',
          help="The object to be analysed. "
-              "It supports the 'module:qualname' syntax")
+              "It supports the `module:qualname` syntax")
     parser.add_argument(
         '-d', '--details', action='store_true',
         help='Display info about the module rather than its source code')
index e56a601c581ae5eca24b5c6f97e699a70a8f7136..6385d971f733041c44077cbd42dccbfd6b573cdf 100644 (file)
@@ -44,13 +44,13 @@ def _colorize_json(json_str, theme):
 def main():
     description = ('A simple command line interface for json module '
                    'to validate and pretty-print JSON objects.')
-    parser = argparse.ArgumentParser(description=description, color=True)
+    parser = argparse.ArgumentParser(description=description)
     parser.add_argument('infile', nargs='?',
                         help='a JSON file to be validated or pretty-printed; '
-                             'defaults to stdin',
+                             'defaults to `stdin`',
                         default='-')
     parser.add_argument('outfile', nargs='?',
-                        help='write the output of infile to outfile',
+                        help='write the output of `infile` to `outfile`',
                         default=None)
     parser.add_argument('--sort-keys', action='store_true', default=False,
                         help='sort the output of dictionaries alphabetically by key')
@@ -58,7 +58,7 @@ def main():
                         help='disable escaping of non-ASCII characters')
     parser.add_argument('--json-lines', action='store_true', default=False,
                         help='parse input using the JSON Lines format. '
-                        'Use with --no-indent or --compact to produce valid JSON Lines output.')
+                        'Use with `--no-indent` or `--compact` to produce valid JSON Lines output.')
     group = parser.add_mutually_exclusive_group()
     group.add_argument('--indent', default=4, type=int,
                        help='separate items with newlines and use this number '
index ad18db09f6b3402c2cdd3ce2b3a11ecd3c2daf25..6d9278bccf927edc34122dcd94fb47498a99184b 100644 (file)
@@ -712,7 +712,7 @@ def _parse_args(args):
     from argparse import ArgumentParser
 
     parser = ArgumentParser(
-        description='map filename extensions to MIME types', color=True
+        description='map filename extensions to MIME types',
     )
     parser.add_argument(
         '-e', '--extension',
index 569599d349c49e6b102be79e9af19bbd09cecdd3..bdc9caf80ec26eaa66d5b780f196faa24af4255d 100644 (file)
@@ -3757,13 +3757,12 @@ def parse_args():
         description=_usage,
         formatter_class=argparse.RawDescriptionHelpFormatter,
         allow_abbrev=False,
-        color=True,
     )
 
     # Get all the commands out first. For backwards compatibility, we allow
     # -c commands to be after the target.
     parser.add_argument('-c', '--command', action='append', default=[], metavar='command', dest='commands',
-                        help='pdb commands to execute as if given in a .pdbrc file')
+                        help='pdb commands to execute as if given in a `.pdbrc` file')
 
     opts, args = parser.parse_known_args()
 
index 95836afdc2b43e5f94a54e4079c68d97d6923c1d..f92b1fde768fc7de99423f0faba8121f374d40ce 100644 (file)
@@ -1937,7 +1937,6 @@ def _main(args=None):
     import pprint
     parser = argparse.ArgumentParser(
         description='display contents of the pickle files',
-        color=True,
     )
     parser.add_argument(
         'pickle_file',
index 976e218db192980bfa24e1fd49c7095a2dc9abb9..a9711538dae342bc83d49849f62718298d122180 100644 (file)
@@ -2899,7 +2899,7 @@ def _main(args=None):
         help='preserve memo between disassemblies')
     parser.add_argument(
         '-l', '--indentlevel', default=4, type=int,
-        help='the number of blanks by which to indent a new MARK level')
+        help='the number of blanks by which to indent a new `MARK` level')
     parser.add_argument(
         '-a', '--annotate',  action='store_true',
         help='annotate each line with a short opcode description')
index 9d7aa5c66a91cb3b11bbba76d325be0ff86eb41d..36489d4fdd98ae2bd3a6c2760b98ff3e1e014882 100644 (file)
@@ -1400,7 +1400,7 @@ def invalidate_caches():
 def _parse_args(args: list[str] | None):
     import argparse
 
-    parser = argparse.ArgumentParser(color=True)
+    parser = argparse.ArgumentParser()
     parser.add_argument("args", nargs="*", choices=["nonaliased", "terse"])
     parser.add_argument(
         "--terse",
index bc879c43e15965f5db21645bf4657d06089bf29d..9900415ae8a927ec0b053b7510bd3fb67aae70d6 100644 (file)
@@ -389,13 +389,13 @@ def _add_sampling_options(parser):
     sampling_group.add_argument(
         "--native",
         action="store_true",
-        help='Include artificial "<native>" frames to denote calls to non-Python code',
+        help='Include artificial `<native>` frames to denote calls to non-Python code',
     )
     sampling_group.add_argument(
         "--no-gc",
         action="store_false",
         dest="gc",
-        help='Don\'t include artificial "<GC>" frames to denote active garbage collection',
+        help='Don\'t include artificial `<GC>` frames to denote active garbage collection',
     )
     sampling_group.add_argument(
         "--opcodes",
@@ -432,14 +432,14 @@ def _add_mode_options(parser):
         help="Sampling mode: wall (all samples), cpu (only samples when thread is on CPU), "
         "gil (only samples when thread holds the GIL), "
         "exception (only samples when thread has an active exception). "
-        "Incompatible with --async-aware",
+        "Incompatible with `--async-aware`",
     )
     mode_group.add_argument(
         "--async-mode",
         choices=["running", "all"],
         default="running",
         help='Async profiling mode: "running" (only running task) '
-        'or "all" (all tasks including waiting). Requires --async-aware',
+        'or "all" (all tasks including waiting). Requires `--async-aware`',
     )
 
 
@@ -486,7 +486,7 @@ def _add_format_options(parser, include_compression=True, include_binary=True):
         "--diff-flamegraph",
         metavar="BASELINE",
         action=DiffFlamegraphAction,
-        help="Generate differential flamegraph comparing current profile to BASELINE binary file",
+        help="Generate differential flamegraph comparing current profile to `BASELINE` binary file",
     )
     if include_binary:
         format_group.add_argument(
@@ -494,7 +494,7 @@ def _add_format_options(parser, include_compression=True, include_binary=True):
             action="store_const",
             const="binary",
             dest="format",
-            help="Generate high-performance binary format (use 'replay' command to convert)",
+            help="Generate high-performance binary format (use `replay` command to convert)",
         )
     parser.set_defaults(format="pstats", diff_baseline=None)
 
@@ -510,14 +510,14 @@ def _add_format_options(parser, include_compression=True, include_binary=True):
         "-o",
         "--output",
         dest="outfile",
-        help="Output path (default: stdout for pstats text; with -o, pstats is binary). "
-        "Auto-generated for other formats. For heatmap: directory name (default: heatmap_PID)",
+        help="Output path (default: `stdout` for `pstats` text; with `-o`, `pstats` is binary). "
+        "Auto-generated for other formats. For heatmap: directory name (default: `heatmap_PID`)",
     )
     output_group.add_argument(
         "--browser",
         action="store_true",
         help="Automatically open HTML output (flamegraph, heatmap) in browser. "
-        "When using --subprocesses, only the main process opens the browser",
+        "When using `--subprocesses`, only the main process opens the browser",
     )
 
 
@@ -564,13 +564,13 @@ def _add_dump_options(parser):
     dump_group.add_argument(
         "--native",
         action="store_true",
-        help='Include artificial "<native>" frames to denote calls to non-Python code',
+        help='Include artificial `<native>` frames to denote calls to non-Python code',
     )
     dump_group.add_argument(
         "--no-gc",
         action="store_false",
         dest="gc",
-        help='Don\'t include artificial "<GC>" frames to denote active garbage collection',
+        help='Don\'t include artificial `<GC>` frames to denote active garbage collection',
     )
     dump_group.add_argument(
         "--opcodes",
@@ -588,7 +588,7 @@ def _add_dump_options(parser):
         default=argparse.SUPPRESS,
         help='Async stack mode: "running" (only running task) '
         'or "all" (all tasks including waiting, default for dump). '
-        "Requires --async-aware",
+        "Requires `--async-aware`",
     )
     dump_group.add_argument(
         "--blocking",
@@ -998,7 +998,7 @@ Examples:
         "-m",
         "--module",
         action="store_true",
-        help="Run target as a module (like python -m)",
+        help="Run target as a module (like `python -m`)",
     )
     run_parser.add_argument(
         "target",
index 694ea9304da9f94dfb93c928bf0631c65f465abb..7ca479141e01e4ef93f25a41a99b871cd9036b07 100644 (file)
@@ -177,7 +177,7 @@ def main():
     import argparse
 
     description = 'A simple command-line interface for py_compile module.'
-    parser = argparse.ArgumentParser(description=description, color=True)
+    parser = argparse.ArgumentParser(description=description)
     parser.add_argument(
         '-q', '--quiet',
         action='store_true',
index 726a71e782893c88b6c1385f68352b30d51d1f36..4541267bab866a495670c0de88140d92a1a1fb49 100644 (file)
@@ -1016,26 +1016,26 @@ if hasattr(_os, "fork"):
 def _parse_args(arg_list: list[str] | None):
     import argparse
     parser = argparse.ArgumentParser(
-        formatter_class=argparse.RawTextHelpFormatter, color=True)
+        formatter_class=argparse.RawTextHelpFormatter)
     group = parser.add_mutually_exclusive_group()
     group.add_argument(
         "-c", "--choice", nargs="+",
         help="print a random choice")
     group.add_argument(
         "-i", "--integer", type=int, metavar="N",
-        help="print a random integer between 1 and N inclusive")
+        help="print a random integer between 1 and `N` inclusive")
     group.add_argument(
         "-f", "--float", type=float, metavar="N",
-        help="print a random floating-point number between 0 and N inclusive")
+        help="print a random floating-point number between 0 and `N` inclusive")
     group.add_argument(
         "--test", type=int, const=10_000, nargs="?",
         help=argparse.SUPPRESS)
     parser.add_argument("input", nargs="*",
                         help="""\
 if no options given, output depends on the input
-    string or multiple: same as --choice
-    integer: same as --integer
-    float: same as --float""")
+    string or multiple: same as `--choice`
+    integer: same as `--integer`
+    float: same as `--float`""")
     args = parser.parse_args(arg_list)
     return args, parser.format_help()
 
index 8805442b69e08086d7fc958df12c1a580697fb77..ec72c6943907175c7693983364df932b6705fb90 100644 (file)
@@ -87,14 +87,11 @@ class SqliteInteractiveConsole(InteractiveConsole):
 
 
 def main(*args):
-    parser = ArgumentParser(
-        description="Python sqlite3 CLI",
-        color=True,
-    )
+    parser = ArgumentParser(description="Python sqlite3 CLI")
     parser.add_argument(
         "filename", type=str, default=":memory:", nargs="?",
         help=(
-            "SQLite database to open (defaults to ':memory:'). "
+            "SQLite database to open (defaults to `:memory:`). "
             "A new database is created if the file does not previously exist."
         ),
     )
@@ -102,7 +99,7 @@ def main(*args):
         "sql", type=str, nargs="?",
         help=(
             "An SQL query to execute. "
-            "Any returned rows are printed to stdout."
+            "Any returned rows are printed to `stdout`."
         ),
     )
     parser.add_argument(
index 4f47aaab9028d0fc4e7f896ce695bfecf12e4c08..d0e7dec5575047a6ccc5dfbfe56c59ca73c37a30 100644 (file)
@@ -3067,7 +3067,7 @@ def main():
     import argparse
 
     description = 'A simple command-line interface for tarfile module.'
-    parser = argparse.ArgumentParser(description=description, color=True)
+    parser = argparse.ArgumentParser(description=description)
     parser.add_argument('-v', '--verbose', action='store_true', default=False,
                         help='Verbose output')
     parser.add_argument('--filter', metavar='<filtername>',
index 45e229eb19f0f9dacf2e7e2ad118d08841a4e8d0..64c035307e66542d9c175c9a3fccbea30cd383b9 100644 (file)
@@ -245,7 +245,7 @@ def _create_parser():
                             'buildbot workers')
     group.add_argument('--timeout', metavar='TIMEOUT',
                         help='dump the traceback and exit if a test takes '
-                             'more than TIMEOUT seconds; disabled if TIMEOUT '
+                             'more than `TIMEOUT` seconds; disabled if `TIMEOUT` '
                              'is negative or equals to zero')
     group.add_argument('--wait', action='store_true',
                        help='wait for user input, e.g., allow a debugger '
@@ -261,11 +261,11 @@ def _create_parser():
 
     group = parser.add_argument_group('Verbosity')
     group.add_argument('-v', '--verbose', action='count',
-                       help='run tests in verbose mode with output to stdout')
+                       help='run tests in verbose mode with output to `stdout`')
     group.add_argument('-w', '--rerun', action='store_true',
                        help='re-run failed tests in verbose mode')
     group.add_argument('--verbose2', action='store_true', dest='rerun',
-                       help='deprecated alias to --rerun')
+                       help='deprecated alias to `--rerun`')
     group.add_argument('-W', '--verbose3', action='store_true',
                        help='display test output on failure')
     group.add_argument('-q', '--quiet', action='store_true',
@@ -295,22 +295,22 @@ def _create_parser():
                             more_details)
     group.add_argument('-m', '--match', metavar='PAT',
                        dest='match_tests', action=FilterAction, const=True,
-                       help='match test cases and methods with glob pattern PAT')
+                       help='match test cases and methods with glob pattern `PAT`')
     group.add_argument('-i', '--ignore', metavar='PAT',
                        dest='match_tests', action=FilterAction, const=False,
-                       help='ignore test cases and methods with glob pattern PAT')
+                       help='ignore test cases and methods with glob pattern `PAT`')
     group.add_argument('--matchfile', metavar='FILENAME',
                        dest='match_tests',
                        action=FromFileFilterAction, const=True,
-                       help='similar to --match but get patterns from a '
+                       help='similar to `--match` but get patterns from a '
                             'text file, one pattern per line')
     group.add_argument('--ignorefile', metavar='FILENAME',
                        dest='match_tests',
                        action=FromFileFilterAction, const=False,
-                       help='similar to --matchfile but it receives patterns '
+                       help='similar to `--matchfile` but it receives patterns '
                             'from text file to ignore')
     group.add_argument('-G', '--failfast', action='store_true',
-                       help='fail as soon as a test fails (only with -v or -W)')
+                       help='fail as soon as a test fails (only with `-v` or `-W`)')
     group.add_argument('-u', '--use', metavar='RES1,RES2,...',
                        action='extend', type=resources_list,
                        help='specify which special resource intensive tests '
@@ -325,7 +325,7 @@ def _create_parser():
 
     group = parser.add_argument_group('Special runs')
     group.add_argument('-L', '--runleaks', action='store_true',
-                       help='run the leaks(1) command just before exit.' +
+                       help='run the `leaks(1)` command just before exit.' +
                             more_details)
     group.add_argument('-R', '--huntrleaks', metavar='RUNCOUNTS',
                        type=huntrleaks,
@@ -333,20 +333,20 @@ def _create_parser():
                             'very slow).' + more_details)
     group.add_argument('-j', '--multiprocess', metavar='PROCESSES',
                        dest='use_mp', type=int,
-                       help='run PROCESSES processes at once')
+                       help='run `PROCESSES` processes at once')
     group.add_argument('--single-process', action='store_true',
                        dest='single_process',
                        help='always run all tests sequentially in '
-                            'a single process, ignore -jN option, '
+                            'a single process, ignore `-jN` option, '
                             'and failed tests are also rerun sequentially '
                             'in the same process')
     group.add_argument('--parallel-threads', metavar='PARALLEL_THREADS',
                        type=int,
-                       help='run copies of each test in PARALLEL_THREADS at '
+                       help='run copies of each test in `PARALLEL_THREADS` at '
                             'once')
     group.add_argument('-T', '--coverage', action='store_true',
                        dest='trace',
-                       help='turn on code coverage tracing using the trace '
+                       help='turn on code coverage tracing using the `trace` '
                             'module')
     group.add_argument('-D', '--coverdir', metavar='DIR',
                        type=relative_filename,
@@ -356,18 +356,18 @@ def _create_parser():
                        help='put coverage files alongside modules')
     group.add_argument('-t', '--threshold', metavar='THRESHOLD',
                        type=int,
-                       help='call gc.set_threshold(THRESHOLD)')
+                       help='call `gc.set_threshold(THRESHOLD)`')
     group.add_argument('-n', '--nowindows', action='store_true',
                        help='suppress error message boxes on Windows')
     group.add_argument('-F', '--forever', action='store_true',
                        help='run the specified tests in a loop, until an '
-                            'error happens; imply --failfast')
+                            'error happens; imply `--failfast`')
     group.add_argument('--list-tests', action='store_true',
                        help="only write the name of tests that will be run, "
                             "don't execute them")
     group.add_argument('--list-cases', action='store_true',
-                       help='only write the name of test cases that will be run'
-                            ' , don\'t execute them')
+                       help='only write the name of test cases that will be run'
+                            'don\'t execute them')
     group.add_argument('-P', '--pgo', dest='pgo', action='store_true',
                        help='enable Profile Guided Optimization (PGO) training')
     group.add_argument('--pgo-extended', action='store_true',
@@ -390,11 +390,11 @@ def _create_parser():
     group.add_argument('--tempdir', metavar='PATH',
                        help='override the working directory for the test run')
     group.add_argument('--cleanup', action='store_true',
-                       help='remove old test_python_* directories')
+                       help='remove old `test_python_*` directories')
     group.add_argument('--bisect', action='store_true',
-                       help='if some tests fail, run test.bisect_cmd on them')
+                       help='if some tests fail, run `test.bisect_cmd` on them')
     group.add_argument('--pythoninfo', action='store_true',
-                       help="run python -m test.pythoninfo before tests")
+                       help="run `python -m test.pythoninfo` before tests")
     group.add_argument('--dont-add-python-opts', dest='_add_python_opts',
                        action='store_false',
                        help="internal option, don't use it")
index a897d9663c24e2e3b29bd592ccb71f640c8985ce..01bdfd901e30d5e01413fe3f74bdd8c301d6b891 100644 (file)
@@ -299,14 +299,14 @@ Library usage: see the `Timer` class.""",
         "-p",
         "--process",
         action="store_true",
-        help="use time.process_time() (default is time.perf_counter())",
+        help="use `time.process_time()` (default is `time.perf_counter()`)",
     )
     parser.add_argument(
         "-t",
         "--target-time",
         type=float,
         default=default_target_time,
-        help="if --number is 0 the code will run until it takes "
+        help="if `--number` is 0 the code will run until it takes "
         "at least this many seconds (default %(default)s)",
     )
     parser.add_argument(
index 52cf3f0b7ccaa9c2368831279ca11dd48762933a..3545d92c4f5d7ffcef3e3bd4e92bb6ecd3a429c3 100644 (file)
@@ -578,7 +578,7 @@ def _main(args=None):
     parser = argparse.ArgumentParser()
     parser.add_argument(dest='filename', nargs='?',
                         metavar='filename.py',
-                        help='the file to tokenize; defaults to stdin')
+                        help='the file to tokenize; defaults to `stdin`')
     parser.add_argument('-e', '--exact', dest='exact', action='store_true',
                         help='display token names using the exact type')
     args = parser.parse_args(args)
index cd3a6d30661da3979bd24c7f8c3c9240f9b2c7d9..43ec201c4696d1d2e5bdd25cb5df0f33b9859c2d 100644 (file)
@@ -604,7 +604,7 @@ class Trace:
 def main():
     import argparse
 
-    parser = argparse.ArgumentParser(color=True)
+    parser = argparse.ArgumentParser()
     parser.add_argument('--version', action='version', version='trace 2.0')
 
     grp = parser.add_argument_group('Main options',
@@ -612,27 +612,27 @@ def main():
 
     grp.add_argument('-c', '--count', action='store_true',
             help='Count the number of times each line is executed and write '
-                 'the counts to <module>.cover for each module executed, in '
-                 'the module\'s directory. See also --coverdir, --file, '
-                 '--no-report below.')
+                 'the counts to `<module>.cover` for each module executed, in '
+                 'the module\'s directory. See also `--coverdir`, `--file`, '
+                 '`--no-report` below.')
     grp.add_argument('-t', '--trace', action='store_true',
-            help='Print each line to sys.stdout before it is executed')
+            help='Print each line to `sys.stdout` before it is executed')
     grp.add_argument('-l', '--listfuncs', action='store_true',
             help='Keep track of which functions are executed at least once '
-                 'and write the results to sys.stdout after the program exits. '
-                 'Cannot be specified alongside --trace or --count.')
+                 'and write the results to `sys.stdout` after the program exits. '
+                 'Cannot be specified alongside `--trace` or `--count`.')
     grp.add_argument('-T', '--trackcalls', action='store_true',
             help='Keep track of caller/called pairs and write the results to '
-                 'sys.stdout after the program exits.')
+                 '`sys.stdout` after the program exits.')
 
     grp = parser.add_argument_group('Modifiers')
 
     _grp = grp.add_mutually_exclusive_group()
     _grp.add_argument('-r', '--report', action='store_true',
             help='Generate a report from a counts file; does not execute any '
-                 'code. --file must specify the results file to read, which '
-                 'must have been created in a previous run with --count '
-                 '--file=FILE')
+                 'code. `--file` must specify the results file to read, which '
+                 'must have been created in a previous run with `--count` '
+                 '`--file=FILE`')
     _grp.add_argument('-R', '--no-report', action='store_true',
             help='Do not generate the coverage report files. '
                  'Useful if you want to accumulate over several runs.')
@@ -641,14 +641,14 @@ def main():
             help='File to accumulate counts over several runs')
     grp.add_argument('-C', '--coverdir',
             help='Directory where the report files go. The coverage report '
-                 'for <package>.<module> will be written to file '
-                 '<dir>/<package>/<module>.cover')
+                 'for `<package>.<module>` will be written to file '
+                 '`<dir>/<package>/<module>.cover`')
     grp.add_argument('-m', '--missing', action='store_true',
             help='Annotate executable lines that were not executed with '
                  '">>>>>> "')
     grp.add_argument('-s', '--summary', action='store_true',
-            help='Write a brief summary for each file to sys.stdout. '
-                 'Can only be used with --count or --report')
+            help='Write a brief summary for each file to `sys.stdout`. '
+                 'Can only be used with `--count` or `--report`')
     grp.add_argument('-g', '--timing', action='store_true',
             help='Prefix each line with the time since the program started. '
                  'Only used while tracing')
@@ -661,7 +661,7 @@ def main():
                  'module names.')
     grp.add_argument('--ignore-dir', action='append', default=[],
             help='Ignore files in the given directory '
-                 '(multiple directories can be joined by os.pathsep).')
+                 '(multiple directories can be joined by `os.pathsep`).')
 
     parser.add_argument('--module', action='store_true', default=False,
                         help='Trace a module. ')
index be99d93c78cca6c614691f783fa8a6fcfaf1abee..6eeebf9657a3c7b7c4905a44e04e716dc7f80306 100644 (file)
@@ -172,7 +172,7 @@ class TestProgram(object):
                             help='Show local variables in tracebacks')
         parser.add_argument('--durations', dest='durations', type=int,
                             default=None, metavar="N",
-                            help='Show the N slowest test cases (N=0 for all)')
+                            help='Show the `N` slowest test cases (`N=0` for all)')
         if self.failfast is None:
             parser.add_argument('-f', '--failfast', dest='failfast',
                                 action='store_true',
@@ -181,12 +181,12 @@ class TestProgram(object):
         if self.catchbreak is None:
             parser.add_argument('-c', '--catch', dest='catchbreak',
                                 action='store_true',
-                                help='Catch Ctrl-C and display results so far')
+                                help='Catch `Ctrl-C` and display results so far')
             self.catchbreak = False
         if self.buffer is None:
             parser.add_argument('-b', '--buffer', dest='buffer',
                                 action='store_true',
-                                help='Buffer stdout and stderr during tests')
+                                help='Buffer `stdout` and `stderr` during tests')
             self.buffer = False
         if self.testNamePatterns is None:
             parser.add_argument('-k', dest='testNamePatterns',
@@ -197,7 +197,7 @@ class TestProgram(object):
         return parser
 
     def _getMainArgParser(self, parent):
-        parser = argparse.ArgumentParser(parents=[parent], color=True)
+        parser = argparse.ArgumentParser(parents=[parent])
         parser.prog = self.progName
         parser.print_help = self._print_help
 
@@ -208,16 +208,16 @@ class TestProgram(object):
         return parser
 
     def _getDiscoveryArgParser(self, parent):
-        parser = argparse.ArgumentParser(parents=[parent], color=True)
+        parser = argparse.ArgumentParser(parents=[parent])
         parser.prog = '%s discover' % self.progName
         parser.epilog = ('For test discovery all test modules must be '
                          'importable from the top level directory of the '
                          'project.')
 
         parser.add_argument('-s', '--start-directory', dest='start',
-                            help="Directory to start discovery ('.' default)")
+                            help="Directory to start discovery (`.` default)")
         parser.add_argument('-p', '--pattern', dest='pattern',
-                            help="Pattern to match tests ('test*.py' default)")
+                            help="Pattern to match tests (`test*.py` default)")
         parser.add_argument('-t', '--top-level-directory', dest='top',
                             help='Top level directory of project (defaults to '
                                  'start directory)')
index 8c59581464b0d010de0eff4fa3036d5018fdf3f7..4bdcb67775a2ea128ec101ee75334879ecc4d0fa 100644 (file)
@@ -955,7 +955,6 @@ def main():
     parser = argparse.ArgumentParser(
         formatter_class=argparse.ArgumentDefaultsHelpFormatter,
         description="Generate a UUID using the selected UUID function.",
-        color=True,
     )
     parser.add_argument("-u", "--uuid",
                         choices=uuid_funcs.keys(),
@@ -963,14 +962,14 @@ def main():
                         help="function to generate the UUID")
     parser.add_argument("-n", "--namespace",
                         metavar=f"{{any UUID,{','.join(namespaces)}}}",
-                        help="uuid3/uuid5 only: "
+                        help="`uuid3`/`uuid5` only: "
                         "a UUID, or a well-known predefined UUID addressed "
                         "by namespace name")
     parser.add_argument("-N", "--name",
-                        help="uuid3/uuid5 only: "
+                        help="`uuid3`/`uuid5` only: "
                         "name used as part of generating the UUID")
     parser.add_argument("-C", "--count", metavar="NUM", type=int, default=1,
-                        help="generate NUM fresh UUIDs")
+                        help="generate `NUM` fresh UUIDs")
 
     args = parser.parse_args()
     uuid_func = uuid_funcs[args.uuid]
index 002f4ebc988a3b5a9c5ec61fbb81578eeabe0381..0653a43a8b17766525e2cf05364048eca1fc259e 100644 (file)
@@ -621,7 +621,6 @@ def main(args=None):
                                             'activate it, e.g. by '
                                             'sourcing an activate script '
                                             'in its bin directory.',
-                                     color=True,
                                      )
     parser.add_argument('dirs', metavar='ENV_DIR', nargs='+',
                         help='A directory to create the environment in.')
index 97aad6eea509eb54db0c10523f66dccbb9c34069..c2ee0df0ef8885617205108f7cab6c28c67c86d5 100644 (file)
@@ -734,7 +734,7 @@ if sys.platform == "ios":
 def parse_args(arg_list: list[str] | None):
     import argparse
     parser = argparse.ArgumentParser(
-        description="Open URL in a web browser.", color=True,
+        description="Open URL in a web browser.",
     )
     parser.add_argument("url", help="URL to open")
 
index 7a4ef96ea0f07793b76527a691c95fdf9d577107..a1cef18ada9d05d568c577cc4d7bde7e70932340 100644 (file)
@@ -187,16 +187,16 @@ def main(args=None):
     """
     import argparse
 
-    parser = argparse.ArgumentParser(color=True)
+    parser = argparse.ArgumentParser()
     parser.add_argument('--output', '-o', default=None,
             help="The name of the output archive. "
-                 "Required if SOURCE is an archive.")
+                 "Required if `SOURCE` is an archive.")
     parser.add_argument('--python', '-p', default=None,
             help="The name of the Python interpreter to use "
                  "(default: no shebang line).")
     parser.add_argument('--main', '-m', default=None,
             help="The main function of the application "
-                 "(default: use an existing __main__.py).")
+                 "(default: use an existing `__main__.py`).")
     parser.add_argument('--compress', '-c', action='store_true',
             help="Compress files with the deflate method. "
                  "Files are stored uncompressed by default.")
index 1e0cc5f6234f281c906057f23af52801dd3f4226..86c3bc36b695c7916ab6a6b5a89207e56bb96149 100644 (file)
@@ -2328,7 +2328,7 @@ def main(args=None):
     import argparse
 
     description = 'A simple command-line interface for zipfile module.'
-    parser = argparse.ArgumentParser(description=description, color=True)
+    parser = argparse.ArgumentParser(description=description)
     group = parser.add_mutually_exclusive_group(required=True)
     group.add_argument('-l', '--list', metavar='<zipfile>',
                        help='Show listing of a zipfile')
@@ -2341,7 +2341,7 @@ def main(args=None):
     group.add_argument('-t', '--test', metavar='<zipfile>',
                        help='Test if a zipfile is valid')
     parser.add_argument('--metadata-encoding', metavar='<encoding>',
-                        help='Specify encoding of member names for -l, -e and -t')
+                        help='Specify encoding of member names for `-l`, `-e` and `-t`')
     args = parser.parse_args(args)
 
     encoding = args.metadata_encoding
diff --git a/Misc/NEWS.d/next/Library/2026-05-05-00-30-04.gh-issue-142389.4daLzc.rst b/Misc/NEWS.d/next/Library/2026-05-05-00-30-04.gh-issue-142389.4daLzc.rst
new file mode 100644 (file)
index 0000000..4079854
--- /dev/null
@@ -0,0 +1,2 @@
+Add backticks to stdlib argparse help to display in colour. Patch by Hugo
+van Kemenade.