8000 gh-130167: Optimise ``textwrap.dedent()`` by AA-Turner · Pull Request #131919 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-130167: Optimise textwrap.dedent() #131919

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Mar 31, 2025
Prev Previous commit
Next Next commit
Add full stops
  • Loading branch information
AA-Turner committed Mar 30, 2025
commit ecc9cfcff34c5e7e23fce7bd115f44e7eaa1280d
4 changes: 2 additions & 2 deletions Lib/textwrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,13 +429,13 @@ def dedent(text):
if not text:
return text

# If the input is entirely whitespace, return normalized lines
# If the input is entirely whitespace, return normalized lines.
if text.isspace():
return '\n' * text.count('\n')

lines = text.split('\n')

# Get length of leading whitespace, inspired by ``os.path.commonprefix()``
# Get length of leading whitespace, inspired by ``os.path.commonprefix()``.
non_blank_lines = [l for l in lines if l and not l.isspace()]
l1 = min(non_blank_lines)
l2 = max(non_blank_lines)
Expand Down
Loading
0