[New-bugs-announce] [issue34984] Improve error messages in bytes and bytearray constructors

Serhiy Storchaka report at bugs.python.org
Sun Oct 14 12:53:27 EDT 2018


New submission from Serhiy Storchaka <storchaka+cpython at gmail.com>:

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".

----------
assignee: serhiy.storchaka
components: Interpreter Core
messages: 327715
nosy: r.david.murray, serhiy.storchaka
priority: normal
severity: normal
status: open
title: Improve error messages in bytes and bytearray constructors
type: enhancement
versions: Python 3.8

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


More information about the New-bugs-announce mailing list