[issue41924] TextWrap's wrap method throws unhelpful error on bytes object

Josh Rosenberg report at bugs.python.org
Sat Oct 3 21:05:22 EDT 2020


Josh Rosenberg <shadowranger+python at gmail.com> added the comment:

It's not textwrap that's doing it, which is why the error is so unhelpful; the input is assumed to be a str, and the translate method is called on it with a dict argument, which is valid for str.translate, but not for bytes.translate.

You'll get other "unhelpful" error messages for other arguments (e.g. most other built-in types die because they lack an expandtabs method). Is it necessary to provide specific error messages when an API is given a type it never claimed to support? I could see issues with a "check for str" check if someone is implementing their own str-like type that matches the API but gets rejected for not being str.

----------
nosy: +josh.r

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue41924>
_______________________________________


More information about the Python-bugs-list mailing list