Author Ilja Everilä
Recipients Ilja Everilä, terry.reedy
Date 2016-02-29.22:30:32
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
I'm starting to think my initial example code was too simplified and misled from the issue at hand. It very explicitly showed what happens when some class with __iter__ raises and is passed to csv_writerows. Even then:

>>> from import Iterable
>>> class X:
...  def __iter__(self):
...   raise RuntimeError
>>> x = X()
>>> issubclass(X, Iterable)
>>> isinstance(x, Iterable)

The glossary entry for iterable has nothing to say about exceptions. It only requires that they are able to return their members "one at a time". In a moderately complicated class this might be true most of the time, but that's not interesting; that 1 time when it can't is.

Now imagine you have a class with __iter__ using 1..N foreign libraries that all may blow up at the wrong phase of the moon (humor me). With the current implementation you get "TypeError: writerows() argument must be iterable", which goes out of its way to actually mislead you. Just letting the original exception through would be the obviously helpful thing to do. Which is what PyObject_GetIter does, before csv_writerows overwrites it.
Date User Action Args
2016-02-29 22:30:33Ilja Everiläsetrecipients: + Ilja Everilä, terry.reedy
2016-02-29 22:30:33Ilja Everiläsetmessageid: <>
2016-02-29 22:30:33Ilja Everilälinkissue26407 messages
2016-02-29 22:30:32Ilja Everiläcreate