File tree 3 files changed +13
-5
lines changed
3 files changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -765,6 +765,13 @@ def test_subsequent_indent(self):
765
765
# of IndentTestCase!
766
766
class DedentTestCase (unittest .TestCase ):
767
767
768
+ def test_type_error (self ):
769
+ with self .assertRaisesRegex (TypeError , "expected str object, not" ):
770
+ dedent (0 )
771
+
772
+ with self .assertRaisesRegex (TypeError , "expected str object, not" ):
773
+ dedent (b'' )
774
+
768
775
def assertUnchanged (self , text ):
769
776
"""assert that dedent() has no effect on 'text'"""
770
777
self .assertEqual (text , dedent (text ))
Original file line number Diff line number Diff line change @@ -426,10 +426,11 @@ def dedent(text):
426
426
427
427
Entirely blank lines are normalized to a newline character.
428
428
"""
429
- if not text :
430
- return text
431
-
432
- lines = text .split ('\n ' )
429
+ try :
430
+ lines = text .split ('\n ' )
431
+ except (AttributeError , TypeError ):
432
+ msg = f'expected str object, not { type (text ).__qualname__ !r} '
433
+ raise TypeError (msg ) from None
433
434
434
435
# Get length of leading whitespace, inspired by ``os.path.commonprefix()``.
435
436
non_blank_lines = [l for l in lines if l and not l .isspace ()]
Original file line number Diff line number Diff line change @@ -288,7 +288,7 @@ Improve the import time of the :mod:`ast` module by extracting the
288
288
.. nonce: 8M-HVz
289
289
.. section: Library
290
290
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.
292
292
Patch by Adam Turner.
293
293
294
294
..
You can’t perform that action at this time.
0 commit comments