Terry J. Reedy <tjre...@udel.edu> added the comment:

I retested and iter(ob) (1) apparently raises 'not iterable' only when it can 
find neither __iter__ nor __getitem__.  It (2) raises 'non-iterator', as above, 
when it finds  __iter__, calls its, and get a non-iterator.  (3) Exceptions in 
__iter__ are passed through.  (If it finds and wraps __getitem__, errors only 
appear during iteration.)

The current patch for assignment unpacking catches case (1) with 
"v->ob_type->tp_iter == NULL && !PySequence_Check(v))".  Removing this would 
catch case (2) and incidentally case (3) TypeErrors.  Not catching user 
TypeErrors would require looking at the message.  I intentionally am not 
proposing to remove the TypeError check.

Presuming the existence of a PyErr_' function to get exception messages, we 
could simply prefix the existing message with a short 'Cannot unpack. '  The 
same could be done for the other cases in msg307999, but I don't know if they 
are subject to the same need.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue32259>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to