Kaydet (Commit) fbe04b68 authored tarafından 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.
üst 0a1ba709
...@@ -647,6 +647,11 @@ def foo(): ...@@ -647,6 +647,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))
def test_main(): def test_main():
test_support.run_unittest(WrapTestCase, test_support.run_unittest(WrapTestCase,
......
...@@ -403,11 +403,15 @@ def dedent(text): ...@@ -403,11 +403,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)):
break if x != y:
margin = margin[:i]
break
else:
margin = margin[:len(indent)]
# sanity check (testing/debugging only) # sanity check (testing/debugging only)
if 0 and margin: if 0 and margin:
......
...@@ -808,6 +808,7 @@ Mark Levinson ...@@ -808,6 +808,7 @@ Mark Levinson
Mark Levitt Mark Levitt
William Lewis William Lewis
Akira Li Akira Li
Robert Li
Xuanji Li Xuanji Li
Robert van Liere Robert van Liere
Ross Light Ross Light
......
...@@ -46,6 +46,10 @@ Core and Builtins ...@@ -46,6 +46,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 #21709: Fix the logging module to not depend upon __file__ being set - Issue #21709: Fix the logging module to not depend upon __file__ being set
properly to get the filename of its caller from the stack. This allows it properly to get the filename of its caller from the stack. This allows it
to work if run in a frozen or embedded environment where the module's to work if run in a frozen or embedded environment where the module's
......
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