Skip to content

Commit f2050ae

Browse files
committed
Remove early-exit check for whitespace-only input, as suggested by Pieter Eendebak
1 parent 311ac87 commit f2050ae

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

Lib/textwrap.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -429,16 +429,13 @@ def dedent(text):
429429
if not text:
430430
return text
431431

432-
# If the input is entirely whitespace, return normalized lines.
433-
if text.isspace():
434-
return '\n' * text.count('\n')
435-
436432
lines = text.split('\n')
437433

438434
# Get length of leading whitespace, inspired by ``os.path.commonprefix()``.
439435
non_blank_lines = [l for l in lines if l and not l.isspace()]
440-
l1 = min(non_blank_lines)
441-
l2 = max(non_blank_lines)
436+
l1 = min(non_blank_lines, default='')
437+
l2 = max(non_blank_lines, default='')
438+
margin = 0
442439
for margin, c in enumerate(l1):
443440
if c != l2[margin] or c not in ' \t':
444441
break

0 commit comments

Comments
 (0)