Steven D'Aprano <[email protected]> added the comment:
I think this suggested enhancement is unreasonable and of limited usefulness,
and even if it were useful, too specialised to bother with.
The obvious message is badly misleading. When I read this:
TypeError: 'tuple' object is not callable, a comma may be missing
I look inside the tuple for a missing comma. But that's not the problem, and
the error message sends me on a wild goose chase wondering how on earth a
missing comma causes Python to try calling my tuple. I've been programming in
Python for 15+ years and it mislead me -- what do you think it will do to
beginners?
The problem is that the tuple is inside a list, and the LIST is missing a comma.
What about this example?
result = function(
"the error has nothing to do with tuples" # oops missed a comma
(2, 3, 4),
None
)
Should the error message say something like:
TypeError: 'str' object is not callable, perhaps it is embedded in a list,
tuple,
function call or some other place you need a comma, and you forgot one
or more commas?
I don't think so. Besides, most of the time when you get this TypeError, it
will be because you genuinely tried to call what you thought was a function but
wasn't, and the hint is pointless.
You tried to call a tuple as if it were a function. The reason for that is that
you left out a comma in a list, but there are many other reasons that could
happen, and "I frequently forget to add commas to lists" is a far
too-specialised failure mode to single it out in the error message.
It is unreasonable to expect Python to debug your code for you. It tells you
what you did wrong -- you called a tuple as a function -- and it is up to you
to determine why.
----------
nosy: +stevenjd
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue15248>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com