Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bytearray.extend: Misleading error message #115323

Closed
smurfix opened this issue Feb 12, 2024 · 2 comments · Fixed by #115332
Closed

bytearray.extend: Misleading error message #115323

smurfix opened this issue Feb 12, 2024 · 2 comments · Fixed by #115332
Labels
type-bug An unexpected behavior, bug, or error

Comments

@smurfix
Copy link

smurfix commented Feb 12, 2024

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

@terryjreedy
Copy link
Member

Behavior same back to 3.11. The currently message is erroneous enough that backporting should be considered.

terryjreedy added a commit that referenced this issue Feb 24, 2024
…th str (#115332)

Perform str check after TypeError is raised
---------

Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Feb 24, 2024
…end with str (pythonGH-115332)

Perform str check after TypeError is raised
---------

(cherry picked from commit 948acd6)

Co-authored-by: Jay Ting <65202977+jayasting98@users.noreply.github.com>
Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Feb 24, 2024
…end with str (pythonGH-115332)

Perform str check after TypeError is raised
---------

(cherry picked from commit 948acd6)

Co-authored-by: Jay Ting <65202977+jayasting98@users.noreply.github.com>
Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
@terryjreedy
Copy link
Member

After adding the backport tags and having them start, I changed my mind and closed them.

woodruffw pushed a commit to woodruffw-forks/cpython that referenced this issue Mar 4, 2024
…end with str (python#115332)

Perform str check after TypeError is raised
---------

Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
diegorusso pushed a commit to diegorusso/cpython that referenced this issue Apr 17, 2024
…end with str (python#115332)

Perform str check after TypeError is raised
---------

Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants