This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author sobolevn
Recipients AbcSxyZ, lys.nikolaou, pablogsal, sobolevn
Date 2021-10-23.16:11:02
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1635005462.66.0.566649016847.issue45580@roundup.psfhosted.org>
In-reply-to
Content
I confirm this happens on all recent Python versions.

The source of this problem is that `argparse` uses `regex` module to replace some substrings. Direct link: https://github.com/python/cpython/blame/8ce20bbdd6d2b1277a5e74154fcdcef2cb0fee49/Lib/argparse.py#L487

Quick debug showed that without this line these tests fail:

```
======================================================================
FAIL: test_help_when_required (test.test_argparse.TestMutuallyExclusiveFirstSuppressed)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/sobolev/Desktop/cpython/Lib/test/test_argparse.py", line 2649, in test_help_when_required
    self.assertEqual(format_help(), textwrap.dedent(help))
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: 'usage: PROG [-h] (-y)\n\noptions:\n  -h, --help  show this[42 chars]lp\n' != 'usage: PROG [-h] -y\n\noptions:\n  -h, --help  show this h[40 chars]lp\n'
- usage: PROG [-h] (-y)
?                  -  -
+ usage: PROG [-h] -y
  
  options:
    -h, --help  show this help message and exit
    -y          y help


======================================================================
FAIL: test_usage_when_required (test.test_argparse.TestMutuallyExclusiveFirstSuppressed)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/sobolev/Desktop/cpython/Lib/test/test_argparse.py", line 2639, in test_usage_when_required
    self.assertEqual(format_usage(), textwrap.dedent(expected_usage))
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: 'usage: PROG [-h] (-y)\n' != 'usage: PROG [-h] -y\n'
- usage: PROG [-h] (-y)
?                  -  -
+ usage: PROG [-h] -y


======================================================================
FAIL: test_help_when_required (test.test_argparse.TestMutuallyExclusiveFirstSuppressedParent)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/sobolev/Desktop/cpython/Lib/test/test_argparse.py", line 2649, in test_help_when_required
    self.assertEqual(format_help(), textwrap.dedent(help))
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: 'usage: PROG [-h] (-y)\n\noptions:\n  -h, --help  show this[42 chars]lp\n' != 'usage: PROG [-h] -y\n\noptions:\n  -h, --help  show this h[40 chars]lp\n'
- usage: PROG [-h] (-y)
?                  -  -
+ usage: PROG [-h] -y
  
  options:
    -h, --help  show this help message and exit
    -y          y help


======================================================================
FAIL: test_usage_when_required (test.test_argparse.TestMutuallyExclusiveFirstSuppressedParent)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/sobolev/Desktop/cpython/Lib/test/test_argparse.py", line 2639, in test_usage_when_required
    self.assertEqual(format_usage(), textwrap.dedent(expected_usage))
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: 'usage: PROG [-h] (-y)\n' != 'usage: PROG [-h] -y\n'
- usage: PROG [-h] (-y)
?                  -  -
+ usage: PROG [-h] -y


----------------------------------------------------------------------
Ran 1672 tests in 23.258s

FAILED (failures=4)
test test_argparse failed
test_argparse failed (4 failures)

== Tests result: FAILURE ==

1 test failed:
    test_argparse

Total duration: 25.6 sec
Tests result: FAILURE
```
History
Date User Action Args
2021-10-23 16:11:02sobolevnsetrecipients: + sobolevn, lys.nikolaou, pablogsal, AbcSxyZ
2021-10-23 16:11:02sobolevnsetmessageid: <1635005462.66.0.566649016847.issue45580@roundup.psfhosted.org>
2021-10-23 16:11:02sobolevnlinkissue45580 messages
2021-10-23 16:11:02sobolevncreate