Ilja Everilä added the comment:

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 collections.abc import Iterable
>>> class X:
...  def __iter__(self):
...   raise RuntimeError
... 
>>> x = X()
>>> issubclass(X, Iterable)
True
>>> isinstance(x, Iterable)
True

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.

----------

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

Reply via email to