Commit f8152c67 authored by Serhiy Storchaka's avatar Serhiy Storchaka

Issue #21827: Fixed textwrap.dedent() for the case when largest common

whitespace is a substring of smallest leading whitespace.
Based on patch by Robert Li.
parents 44b1020c ea4cb63e
...@@ -748,6 +748,11 @@ def foo(): ...@@ -748,6 +748,11 @@ def foo():
expect = "hello there\n how are you?" expect = "hello there\n how are you?"
self.assertEqual(expect, dedent(text)) self.assertEqual(expect, dedent(text))
# test margin is smaller than smallest indent
text = " \thello there\n \thow are you?\n \tI'm fine, thanks"
expect = " \thello there\n \thow are you?\n\tI'm fine, thanks"
self.assertEqual(expect, dedent(text))
# Test textwrap.indent # Test textwrap.indent
class IndentTestCase(unittest.TestCase): class IndentTestCase(unittest.TestCase):
......
...@@ -444,11 +444,15 @@ def dedent(text): ...@@ -444,11 +444,15 @@ def dedent(text):
elif margin.startswith(indent): elif margin.startswith(indent):
margin = indent margin = indent
# Current line and previous winner have no common whitespace: # Find the largest common whitespace between current line and previous
# there is no margin. # winner.
else: else:
margin = "" for i, (x, y) in enumerate(zip(margin, indent)):
if x != y:
margin = margin[:i]
break break
else:
margin = margin[:len(indent)]
# sanity check (testing/debugging only) # sanity check (testing/debugging only)
if 0 and margin: if 0 and margin:
......
...@@ -847,6 +847,7 @@ Mark Levitt ...@@ -847,6 +847,7 @@ Mark Levitt
Ivan Levkivskyi Ivan Levkivskyi
William Lewis William Lewis
Akira Li Akira Li
Robert Li
Xuanji Li Xuanji Li
Robert van Liere Robert van Liere
Ross Light Ross Light
......
...@@ -45,6 +45,10 @@ Core and Builtins ...@@ -45,6 +45,10 @@ Core and Builtins
Library Library
------- -------
- Issue #21827: Fixed textwrap.dedent() for the case when largest common
whitespace is a substring of smallest leading whitespace.
Based on patch by Robert Li.
- Issue #25447: The lru_cache() wrapper objects now can be copied and pickled - Issue #25447: The lru_cache() wrapper objects now can be copied and pickled
(by returning the original object unchanged). (by returning the original object unchanged).
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment