Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.

Commit 7fe28ad

Browse files
committed
Issue python#29290: argparse help messages won't wrap at non-breaking spaces.
1 parent d7d87ca commit 7fe28ad

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

Lib/argparse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def __init__(self,
176176
self._root_section = self._Section(self, None)
177177
self._current_section = self._root_section
178178

179-
self._whitespace_matcher = _re.compile(r'\s+')
179+
self._whitespace_matcher = _re.compile(r'\s+', _re.ASCII)
180180
self._long_break_matcher = _re.compile(r'\n\n\n+')
181181

182182
# ===============================

Lib/test/test_argparse.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1943,6 +1943,23 @@ def test_help_extra_prefix_chars(self):
19431943
++foo foo help
19441944
'''))
19451945

1946+
def test_help_non_breaking_spaces(self):
1947+
parser = ErrorRaisingArgumentParser(
1948+
prog='PROG', description='main description')
1949+
parser.add_argument(
1950+
"--non-breaking", action='store_false',
1951+
help='help message containing non-breaking spaces shall not '
1952+
'wrap\N{NO-BREAK SPACE}at non-breaking spaces')
1953+
self.assertEqual(parser.format_help(), textwrap.dedent('''\
1954+
usage: PROG [-h] [--non-breaking]
1955+
1956+
main description
1957+
1958+
optional arguments:
1959+
-h, --help show this help message and exit
1960+
--non-breaking help message containing non-breaking spaces shall not
1961+
wrap\N{NO-BREAK SPACE}at non-breaking spaces
1962+
'''))
19461963

19471964
def test_help_alternate_prefix_chars(self):
19481965
parser = self._get_parser(prefix_chars='+:/')

Misc/NEWS

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@ Core and Builtins
1313
Library
1414
-------
1515

16+
- Issue #29290: Fix a regression in argparse that help messages would wrap at
17+
non-breaking spaces.
18+
1619
- Issue #28735: Fixed the comparison of mock.MagickMock with mock.ANY.
1720

18-
- Issue #29011: Fix an important omission by adding Deque to the typing module.
21+
- Issue #29011: Fix an important omission by adding Deque to the typing module.
1922

2023
- Issue #29219: Fixed infinite recursion in the repr of uninitialized
2124
ctypes.CDLL instances.

0 commit comments

Comments
 (0)