[Python-ideas] Showing qualified names when a function call fails

Chris Angelico rosuav at gmail.com
Tue Oct 25 09:58:31 EDT 2016


On Wed, Oct 26, 2016 at 12:20 AM, Michel Desmoulin
<desmoulinmichel at gmail.com> wrote:
> list, set and tuple less not as good:
>
>     >>> tuple(foo)
>
>     TypeError: 'int' object is not iterable
>
> No raiser, no value given. It's hard to find out what's the problem is. The
> biggest issue here is that if you have a long line with tuple() in the
> middle, yuou need to know the problem comes from tuple.
>
> Another problem is that many people don't know what iterable means.
>
> A better error message would be:
>
> TypeError: tuple() only accept iterables (any object you can use a for loop
> on). But it received '1', which is of type <int>.

-1 on this one. It doesn't really add very much - "iterable" is a good
keyword that anyone can put into a search engine. Adding the repr of
the object that was passed is nice if it's an integer, but less so if
you passed in some huge object.

If your lines of code are so complicated that you can't pinpoint the
cause of the TypeError, the solution is probably to break the line.

> Some things deserve a big explanation to solve the problem. It would be nice
> to add a link to official tutorial in the documentation.
>
> E.G, encoding is a big one:
>
>    In [8]: b'é' + 'é'
>      File "<ipython-input-8-cfac1add5f26>", line 1
>        b'é' + 'é'
>               ^
>    SyntaxError: bytes can only contain ASCII literal characters.
>
> This is not helpful to somebody unaware of the difference between text and
> bytes.

Someone unaware of the difference between text and bytes probably
isn't messing with code that has b"..." strings in it. Ultimately,
there's not a lot you can do about that; people just have to learn
certain things, and quite probably, searching the web for this error
message will find good information (it did for me).

-0.5 on this change.

ChrisA


More information about the Python-ideas mailing list