Skip to content

Commit 4c820cd

Browse files
committed
Improve the error case for textwrap.dedent
1 parent ea23c89 commit 4c820cd

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

Lib/textwrap.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,11 @@ def dedent(text):
429429
if not text:
430430
return text
431431

432-
lines = text.split('\n')
432+
try:
433+
lines = text.split('\n')
434+
except AttributeError:
435+
msg = f'expected str object, not {type(text).__qualname__!r}'
436+
raise TypeError(msg) from None
433437

434438
# Get length of leading whitespace, inspired by ``os.path.commonprefix()``.
435439
non_blank_lines = [l for l in lines if l and not l.isspace()]

Misc/NEWS.d/3.14.0a7.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ Improve the import time of the :mod:`ast` module by extracting the
288288
.. nonce: 8M-HVz
289289
.. section: Library
290290
291-
Improved performance of :func:`textwrap.dedent` by an average of ~1.3x.
291+
Improved performance of :func:`textwrap.indent` by an average of ~1.3x.
292292
Patch by Adam Turner.
293293

294294
..

0 commit comments

Comments
 (0)