Message260673
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. |
|
Date |
User |
Action |
Args |
2016-02-22 12:38:53 | Ilja Everilä | set | recipients:
+ Ilja Everilä |
2016-02-22 12:38:53 | Ilja Everilä | set | messageid: <1456144733.82.0.26880413097.issue26407@psf.upfronthosting.co.za> |
2016-02-22 12:38:53 | Ilja Everilä | link | issue26407 messages |
2016-02-22 12:38:53 | Ilja Everilä | create | |
|