Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Improve the error message for bytes
  • Loading branch information
AA-Turner committed Apr 18, 2025
commit ec839ff387878e231c0356d6a189833349d4ee8d
3 changes: 3 additions & 0 deletions Lib/test/test_textwrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,9 @@ def test_type_error(self):
with self.assertRaisesRegex(TypeError, "expected str object, not"):
dedent(0)

with self.assertRaisesRegex(TypeError, "expected str object, not"):
dedent(b'')

def assertUnchanged(self, text):
"""assert that dedent() has no effect on 'text'"""
self.assertEqual(text, dedent(text))
Expand Down
2 changes: 1 addition & 1 deletion Lib/textwrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ def dedent(text):

try:
lines = text.split('\n')
except AttributeError:
except (AttributeError, TypeError):
msg = f'expected str object, not {type(text).__qualname__!r}'
raise TypeError(msg) from None

Expand Down