cpython: faeeb8dbe432 (original) (raw)
Mercurial > cpython
changeset 98876:faeeb8dbe432 3.4
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. [#21827]
Serhiy Storchaka storchaka@gmail.com | |
---|---|
date | Wed, 28 Oct 2015 21:39:36 +0200 |
parents | 8b1418e5dcc8 |
children | 3f29be82c944 114fb81a08e3 |
files | Lib/test/test_textwrap.py Lib/textwrap.py Misc/ACKS Misc/NEWS |
diffstat | 4 files changed, 18 insertions(+), 4 deletions(-)[+] [-] Lib/test/test_textwrap.py 5 Lib/textwrap.py 12 Misc/ACKS 1 Misc/NEWS 4 |
line wrap: on
line diff
--- a/Lib/test/test_textwrap.py +++ b/Lib/test/test_textwrap.py @@ -732,6 +732,11 @@ def foo(): expect = "hello there\n how are you?" self.assertEqual(expect, dedent(text))
# test margin is smaller than smallest indent[](#l1.7)
text = " \thello there\n \thow are you?\n \tI'm fine, thanks"[](#l1.8)
expect = " \thello there\n \thow are you?\n\tI'm fine, thanks"[](#l1.9)
self.assertEqual(expect, dedent(text))[](#l1.10)
Test textwrap.indent
class IndentTestCase(unittest.TestCase):
--- a/Lib/textwrap.py +++ b/Lib/textwrap.py @@ -429,11 +429,15 @@ def dedent(text): elif margin.startswith(indent): margin = indent
# Current line and previous winner have no common whitespace:[](#l2.7)
# there is no margin.[](#l2.8)
# Find the largest common whitespace between current line and previous[](#l2.9)
# winner.[](#l2.10) else:[](#l2.11)
margin = ""[](#l2.12)
break[](#l2.13)
for i, (x, y) in enumerate(zip(margin, indent)):[](#l2.14)
if x != y:[](#l2.15)
margin = margin[:i][](#l2.16)
break[](#l2.17)
else:[](#l2.18)
margin = margin[:len(indent)][](#l2.19)
# sanity check (testing/debugging only) if 0 and margin:
--- a/Misc/ACKS +++ b/Misc/ACKS @@ -823,6 +823,7 @@ Mark Levitt Ivan Levkivskyi William Lewis Akira Li +Robert Li Xuanji Li Robert van Liere Ross Light
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -96,6 +96,10 @@ Core and Builtins Library ------- +- Issue #21827: Fixed textwrap.dedent() for the case when largest common