This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: TextWrap's wrap method throws unhelpful error on bytes object
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.8
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: ThePokestarFan, josh.r
Priority: normal Keywords: patch

Created on 2020-10-04 00:54 by ThePokestarFan, last changed 2022-04-11 14:59 by admin. This issue is now closed.

File name Uploaded Description Edit
traceback.txt ThePokestarFan, 2020-10-04 00:54 Traceback
Pull Requests
URL Status Linked Edit
PR 22534 closed ThePokestarFan, 2020-10-04 01:02
Messages (3)
msg377910 - (view) Author: (ThePokestarFan) * Date: 2020-10-04 00:54
The wrap() method of the TextWrapper class (and the module-level wrap method) throws an unhelpful TypeError upon getting a bytes object.
msg377912 - (view) Author: Josh Rosenberg (josh.r) * (Python triager) Date: 2020-10-04 01:05
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.
msg377913 - (view) Author: (ThePokestarFan) * Date: 2020-10-04 01:15
You're most likely right, so I'll close it. The lesson is most likely to not use weird arguments, but modules such as datetime warn against it, so I was surprised.
Date User Action Args
2022-04-11 14:59:36adminsetgithub: 86090
2020-10-04 01:15:37ThePokestarFansetstatus: open -> closed
stage: patch review -> resolved
2020-10-04 01:15:20ThePokestarFansetmessages: + msg377913
2020-10-04 01:05:22josh.rsetnosy: + josh.r
messages: + msg377912
2020-10-04 01:02:33ThePokestarFansetkeywords: + patch
stage: patch review
pull_requests: + pull_request21537
2020-10-04 00:54:49ThePokestarFancreate