[Python-checkins] cpython (3.5): Issue #29290: argparse help messages won't wrap at non-breaking spaces.
xiang.zhang
python-checkins at python.org
Sun Jan 22 01:43:17 EST 2017
https://hg.python.org/cpython/rev/98cde683b9c6
changeset: 106260:98cde683b9c6
branch: 3.5
parent: 106257:1f30e114cbc8
user: Xiang Zhang <angwerzx at 126.com>
date: Sun Jan 22 14:37:22 2017 +0800
summary:
Issue #29290: argparse help messages won't wrap at non-breaking spaces.
files:
Lib/argparse.py | 2 +-
Lib/test/test_argparse.py | 17 +++++++++++++++++
Misc/NEWS | 5 ++++-
3 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/Lib/argparse.py b/Lib/argparse.py
--- a/Lib/argparse.py
+++ b/Lib/argparse.py
@@ -176,7 +176,7 @@
self._root_section = self._Section(self, None)
self._current_section = self._root_section
- self._whitespace_matcher = _re.compile(r'\s+')
+ self._whitespace_matcher = _re.compile(r'\s+', _re.ASCII)
self._long_break_matcher = _re.compile(r'\n\n\n+')
# ===============================
diff --git a/Lib/test/test_argparse.py b/Lib/test/test_argparse.py
--- a/Lib/test/test_argparse.py
+++ b/Lib/test/test_argparse.py
@@ -1943,6 +1943,23 @@
++foo foo help
'''))
+ def test_help_non_breaking_spaces(self):
+ parser = ErrorRaisingArgumentParser(
+ prog='PROG', description='main description')
+ parser.add_argument(
+ "--non-breaking", action='store_false',
+ help='help message containing non-breaking spaces shall not '
+ 'wrap\N{NO-BREAK SPACE}at non-breaking spaces')
+ self.assertEqual(parser.format_help(), textwrap.dedent('''\
+ usage: PROG [-h] [--non-breaking]
+
+ main description
+
+ optional arguments:
+ -h, --help show this help message and exit
+ --non-breaking help message containing non-breaking spaces shall not
+ wrap\N{NO-BREAK SPACE}at non-breaking spaces
+ '''))
def test_help_alternate_prefix_chars(self):
parser = self._get_parser(prefix_chars='+:/')
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -13,9 +13,12 @@
Library
-------
+- Issue #29290: Fix a regression in argparse that help messages would wrap at
+ non-breaking spaces.
+
- Issue #28735: Fixed the comparison of mock.MagickMock with mock.ANY.
-- Issue #29011: Fix an important omission by adding Deque to the typing module.
+- Issue #29011: Fix an important omission by adding Deque to the typing module.
- Issue #29219: Fixed infinite recursion in the repr of uninitialized
ctypes.CDLL instances.
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list