Skip to content

Commit 138caa2

Browse files
committed
Update docs, docstring and tests
1 parent 6da5763 commit 138caa2

3 files changed

Lines changed: 15 additions & 8 deletions

File tree

Doc/library/argparse.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -638,13 +638,14 @@ are set.
638638
.. versionadded:: 3.14
639639

640640
To highlight inline code in your description, epilog, or argument ``help``
641-
text, you can use backticks::
641+
text, you can use single or double backticks::
642642

643643
>>> parser = argparse.ArgumentParser(
644644
... formatter_class=argparse.RawDescriptionHelpFormatter,
645+
... description='Run ``python -m myapp`` to start.',
645646
... epilog='''Examples:
646647
... `python -m myapp --verbose`
647-
... `python -m myapp --config settings.json`
648+
... ``python -m myapp --config settings.json``
648649
... ''')
649650
>>> parser.add_argument('--foo', help='set the `foo` value')
650651

Lib/argparse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ def _apply_text_markup(self, text):
529529
"""Apply color markup to text.
530530
531531
Supported markup:
532-
`...` - inline code (rendered with prog_extra color)
532+
`...` or ``...`` - inline code (rendered with prog_extra color)
533533
534534
When colors are disabled, backticks are preserved as-is.
535535
"""

Lib/test/test_argparse.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7620,21 +7620,25 @@ def test_backtick_markup_in_description(self):
76207620
parser = argparse.ArgumentParser(
76217621
prog='PROG',
76227622
color=True,
7623-
description='Run `python -m myapp` to start.',
7623+
description='Run `python myapp` or ``python -m myapp`` to start.',
76247624
)
76257625

76267626
prog_extra = self.theme.prog_extra
76277627
reset = self.theme.reset
76287628

76297629
help_text = parser.format_help()
7630-
self.assertIn(f'Run {prog_extra}python -m myapp{reset} to start.',
7631-
help_text)
7630+
self.assertIn(
7631+
f'Run {prog_extra}python myapp{reset} or '
7632+
f'{prog_extra}python -m myapp{reset} to start.',
7633+
help_text,
7634+
)
7635+
self.assertNotIn("`", help_text)
76327636

76337637
def test_backtick_markup_multiple(self):
76347638
parser = argparse.ArgumentParser(
76357639
prog='PROG',
76367640
color=True,
7637-
epilog='Try `app run` or `app test`.',
7641+
epilog='Try `app run` or ``app test``.',
76387642
)
76397643

76407644
prog_extra = self.theme.prog_extra
@@ -7643,17 +7647,19 @@ def test_backtick_markup_multiple(self):
76437647
help_text = parser.format_help()
76447648
self.assertIn(f'{prog_extra}app run{reset}', help_text)
76457649
self.assertIn(f'{prog_extra}app test{reset}', help_text)
7650+
self.assertNotIn('`', help_text)
76467651

76477652
def test_backtick_markup_not_applied_when_color_disabled(self):
76487653
# When color is disabled, backticks are preserved as-is
76497654
parser = argparse.ArgumentParser(
76507655
prog='PROG',
76517656
color=False,
7652-
epilog='Example: `python -m myapp`',
7657+
epilog='Examples: `python -m myapp` or ``python -m myapp --x``',
76537658
)
76547659

76557660
help_text = parser.format_help()
76567661
self.assertIn('`python -m myapp`', help_text)
7662+
self.assertIn('``python -m myapp --x``', help_text)
76577663
self.assertNotIn('\x1b[', help_text)
76587664

76597665
def test_backtick_markup_with_format_string(self):

0 commit comments

Comments
 (0)