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: TypeError gives wrong reserved name
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.9, Python 3.8
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: eric.smith, jason.schwefel78, rhettinger
Priority: normal Keywords:

Created on 2020-10-22 15:38 by jason.schwefel78, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (6)
msg379300 - (view) Author: Jason Schwefel (jason.schwefel78) Date: 2020-10-22 15:38
The following code gives a "TypeError: 'str' object is not callable" exception:

int = ''
s = '3500:day'
a = s.split(':')
i = int(a[0])

Proper exception message should be "TypeError: 'int' object is not callable" 

Only able to test on 3.8 and 3.9
msg379305 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2020-10-22 15:44
You've rebound "int" to a string. I think the error message is correct.

Here's a simpler case:

>>> int = ''
>>> int
''
>>> int()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'str' object is not callable

What do you expect to gain with the "int = ''" statement?
msg379314 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2020-10-22 16:38
I should point out that this is the same as doing:

>>> ''()
<stdin>:1: SyntaxWarning: 'str' object is not callable; perhaps you missed a comma?
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'str' object is not callable

Except for the SyntaxWarning part, where the compiler is trying to be helpful.
msg379316 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2020-10-22 17:06
Closing as "not a bug".
msg379320 - (view) Author: Jason Schwefel (jason.schwefel78) Date: 2020-10-22 18:51
>What do you expect to gain with the "int = ''" statement?

I did not expect anything. I made a mistake in my initial code and the error message indicated that I rebound 'str'. I could not find where I had used 'str' as a variable name. If it would have said 'int', as that was the function that I rebound as a variable name, I would have immediately known what to look for.

I understand that it is mostly cosmetic, but I am sure I am not the first person that went down the wrong path because of this. 

I understand that I was using the variable named 'int' as a string and therefore referencing it as 'str' object is technically correct. However, I am still relatively new to Python, as many others are, and the the error message could be a bit more clear.
msg379322 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2020-10-22 18:59
Unfortunately there's not much that can be done about this. The code that writes that error message only knows about objects, which don't have names, only types and values.
History
Date User Action Args
2022-04-11 14:59:37adminsetgithub: 86284
2020-10-22 18:59:39eric.smithsetmessages: + msg379322
2020-10-22 18:51:42jason.schwefel78setmessages: + msg379320
2020-10-22 17:06:15rhettingersetstatus: open -> closed

nosy: + rhettinger
messages: + msg379316

resolution: not a bug
stage: resolved
2020-10-22 16:38:14eric.smithsetmessages: + msg379314
2020-10-22 15:44:53eric.smithsetnosy: + eric.smith
messages: + msg379305
2020-10-22 15:38:20jason.schwefel78create