[Python-Dev] 2.2a3 error messages

Tim Peters tim@zope.com
Tue, 11 Sep 2001 14:31:25 -0400


[/F]
> ...
> is there any chance of getting the old, far more helpful "unpack
> non-sequence" and "loop over non-sequence" error messages
> back before 2.2 final?

[Guido]
> Can you show an example of what went wrong?  Is it just the
> distinction between "unpack" vs. "loop over"?  I would like to make
> the errors more helpful, but I'm not sure where to start.

"iter() of non-sequence" is the msg set by PyObject_GetIter() whenever it
can't get an iterator *at all*, hence every call site for PyObject_GetIter()
*may* end up leaving this msg as-is.  Some do:

>>> for i in 3:
...  pass
...
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: iter() of non-sequence

Some don't:

>>> map(str, 3)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: argument 2 to map() must support iteration
>>>

But "iter() of non-sequence" isn't the only flavor of TypeError
PyObject_GetIter() may raise, and indeed when I fiddled map's msg I was
acutely aware that I may be stomping on some other kind of error entirely;
but in the specific case of map, which accepts any number of arguments, I
thought it was important to spell out which one was giving trouble.

>>> map(str, [], [], [], 3, [])
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: argument 5 to map() must support iteration
>>>

OTOH, given that for-loop semantics are now defined in terms of iterators, I
see nothing wrong with "iter() of non-sequence" in the for-loop example.
Yes, it's different now, but so are for-loops.

So I think this takes exhaustive case-by-case anaylsis, and since /F won't
agree with me about the for-loop example anyway, it's a preference pit.