Skip to content

bytearray.extend: Misleading error message #115323

@smurfix

Description

@smurfix

Bug description:

b=bytearray(b"abc")
b.extend('def')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'str' object cannot be interpreted as an integer```

… except that bytes.extend doesn't even accept integers as arguments; the error refers to the first element of the string, which happens also to be a string in Python. Meh.

Could CPython please complain about requiring the string to be encoded instead?

CPython versions tested on:

main branch

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions