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: Two error messages inconsistent
Type: Stage:
Components: Versions: Python 3.0
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: chester, georg.brandl
Priority: normal Keywords:

Created on 2008-05-25 05:56 by chester, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (3)
msg67319 - (view) Author: Chester (chester) Date: 2008-05-25 05:56
Hello,

I would like to report that two error messages of the Python parser are
not consistent. Please take a look at this:


>>> a = "hello"

>>> a + 1
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: cannot concatenate 'str' and 'int' objects

>>> 1 + a
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'int' and 'str'


When the order of the objects is changed, that should only change the
order of the 'str' and 'int' words in the message.

So if a+1, then
TypeError: cannot concatenate 'str' and 'int' objects

and if 1+a, then
TypeError: cannot concatenate 'int' and 'str' objects
msg67321 - (view) Author: Chester (chester) Date: 2008-05-25 06:13
For the case  a + 1  I recommend:
TypeError: can't concatenate 'str' and 'int' objects

And for the case  1 + a  I recommend:
TypeError: can't concatenate 'int' and 'str' objects


Consistency matters!
msg67327 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2008-05-25 08:03
I don't see a problem here. You may be mislead by the assumption that
the error messages are generated by the parser, which they aren't --
they are generated at runtime by the objects you try to add.

The two types report their failure to do the operation differently --
strings are usually concatenated, so the first one makes sense for
strings, but ints have no such notion.
History
Date User Action Args
2022-04-11 14:56:34adminsetgithub: 47210
2008-05-25 08:03:24georg.brandlsetstatus: open -> closed
resolution: rejected
messages: + msg67327
nosy: + georg.brandl
2008-05-25 06:13:50chestersetmessages: + msg67321
2008-05-25 05:56:48chestercreate