Author Ilja Everilä
Recipients Ilja Everilä
Date 2016-02-22.12:38:53
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1456144733.82.0.26880413097.issue26407@psf.upfronthosting.co.za>
In-reply-to
Content
When passing a class implementing the dunder __iter__ that raises to csv.writer.writerows it hides the original exception and raises a TypeError instead.

In the raised TypeError the __context__ and __cause__ both are None.

For example:

>>> class X:
...  def __iter__(self):
...   raise RuntimeError("I'm hidden")
... 
>>> x = X()
>>> list(x)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 3, in __iter__
RuntimeError: I'm hidden
>>> import csv
>>> csv.writer(open('foo.csv', 'w', newline='')).writerows(x)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: writerows() argument must be iterable
>>> try:
...  csv.writer(open('foo.csv', 'w', newline='')).writerows(x)
... except TypeError as e:
...  e_ = e
>>> e_.__context__ is None
True
>>> e_.__cause__ is None
True

It would seem that for reasons unknown to me either PyObject_GetIter loses the exception context or the call to PyErr_SetString in csv_writerows hides it.
History
Date User Action Args
2016-02-22 12:38:53Ilja Everiläsetrecipients: + Ilja Everilä
2016-02-22 12:38:53Ilja Everiläsetmessageid: <1456144733.82.0.26880413097.issue26407@psf.upfronthosting.co.za>
2016-02-22 12:38:53Ilja Everilälinkissue26407 messages
2016-02-22 12:38:53Ilja Everiläcreate