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: Misleading message “can't concat bytes to str”
Type: Stage: resolved
Components: Interpreter Core Versions:
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: antoine.pietri, serhiy.storchaka
Priority: normal Keywords:

Created on 2017-06-26 10:13 by antoine.pietri, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 2400 closed antoine.pietri, 2017-06-26 10:15
Messages (2)
msg296870 - (view) Author: Antoine Pietri (antoine.pietri) * Date: 2017-06-26 10:13
>>> b'a' + 'a'
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: can't concat bytes to str


This error message is misleading because it is reversed: what is really happening is that we're concatenating str to bytes! When you say "attach A to B" it means B is there first and A is added to it afterwards.

That said, we can't just reverse the message (“can't concat str to bytes”), because having the message reversed compared to the code would be also misleading.

I therefore propose to use “and” (→ “can't concat bytes and str”), which makes more sense and preserve the order.
msg296888 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-06-26 13:06
This already is fixed in issue29116.

>>> b'a' + 'a'
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: can't concat str to bytes
History
Date User Action Args
2022-04-11 14:58:48adminsetgithub: 74947
2017-10-25 03:21:17berker.peksagsetstatus: open -> closed
stage: resolved
2017-06-26 13:06:18serhiy.storchakasetresolution: out of date

messages: + msg296888
nosy: + serhiy.storchaka
2017-06-26 10:41:49antoine.pietrisetcomponents: + Interpreter Core
2017-06-26 10:15:05antoine.pietrisetpull_requests: + pull_request2447
2017-06-26 10:13:37antoine.pietricreate