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.

classification
Title: Improve error messages in bytes and bytearray constructors
Type: enhancement Stage: resolved
Components: Interpreter Core Versions: Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: r.david.murray, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2018-10-14 16:53 by serhiy.storchaka, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 9874 merged serhiy.storchaka, 2018-10-14 16:54
Messages (2)
msg327715 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-10-14 16:53
The proposed PR improves error messages in bytes and bytearray constructors.

1. When pass only encoding or errors to the bytes or bytearray constructor, it raises a TypeError with the message "encoding or errors without sequence argument". But the required argument is not a sequence, it is a string. "sequence argument" will be replaced with "a string argument".

2. Also "encoding or errors" will be replaced with just "encoding" or "errors", as in bytes(0, 'utf-8') and bytes(0, errors='utf-8').

3. When pass an unsupported type to the bytearray constructor, it raises  a TypeError with the message like "'float' object is not iterable". It will be replaced with "cannot convert 'float' object to bytearray" (similar to the message raised in the bytes constructor).

4. When pass an unsupported type to the bytearray's extend() method, it raises  a TypeError with the message like "'float' object is not iterable". It will be replaced with "can't extend bytearray with float".
msg328209 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-10-21 12:29
New changeset 2c2044e789875ea736ec42e216fdbe61816fbe28 by Serhiy Storchaka in branch 'master':
bpo-34984: Improve error messages for bytes and bytearray constructors. (GH-9874)
https://github.com/python/cpython/commit/2c2044e789875ea736ec42e216fdbe61816fbe28
History
Date User Action Args
2022-04-11 14:59:07adminsetgithub: 79165
2018-10-21 12:29:49serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2018-10-21 12:29:16serhiy.storchakasetmessages: + msg328209
2018-10-14 16:54:57serhiy.storchakasetkeywords: + patch
stage: patch review
pull_requests: + pull_request9239
2018-10-14 16:53:27serhiy.storchakacreate