We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent fec6717 commit 19e76d3Copy full SHA for 19e76d3
Lib/textwrap.py
@@ -429,13 +429,14 @@ def dedent(text):
429
if not text:
430
return text
431
432
- lines = text.split('\n')
+ # If the input is entirely whitespace, return normalized lines
433
+ if text.isspace():
434
+ return '\n' * text.count('\n')
435
- non_blank_lines = [l for l in lines if l and not l.isspace()]
- if not non_blank_lines:
436
- return '\n'.join([l if l and not l.isspace() else '' for l in lines])
+ lines = text.split('\n')
437
438
# Get length of leading whitespace, inspired by ``os.path.commonprefix()``
439
+ 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)
442
margin = 0
0 commit comments