mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
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.
This commit is contained in:
parent
68b6874f59
commit
ea4cb63e68
4 changed files with 18 additions and 4 deletions
|
@ -429,11 +429,15 @@ def dedent(text):
|
|||
elif margin.startswith(indent):
|
||||
margin = indent
|
||||
|
||||
# Current line and previous winner have no common whitespace:
|
||||
# there is no margin.
|
||||
# Find the largest common whitespace between current line and previous
|
||||
# winner.
|
||||
else:
|
||||
margin = ""
|
||||
break
|
||||
for i, (x, y) in enumerate(zip(margin, indent)):
|
||||
if x != y:
|
||||
margin = margin[:i]
|
||||
break
|
||||
else:
|
||||
margin = margin[:len(indent)]
|
||||
|
||||
# sanity check (testing/debugging only)
|
||||
if 0 and margin:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue