gh-130167: Improve the error case for `textwrap.dedent` (#132666)

This commit is contained in:
Adam Turner 2025-04-19 16:18:03 +01:00 committed by GitHub
parent c821b715b3
commit e7c5f60efc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 13 additions and 5 deletions

View file

@ -426,10 +426,11 @@ def dedent(text):
Entirely blank lines are normalized to a newline character.
"""
if not text:
return text
lines = text.split('\n')
try:
lines = text.split('\n')
except (AttributeError, TypeError):
msg = f'expected str object, not {type(text).__qualname__!r}'
raise TypeError(msg) from None
# Get length of leading whitespace, inspired by ``os.path.commonprefix()``.
non_blank_lines = [l for l in lines if l and not l.isspace()]