New submission from Ilja Everilä: 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. ---------- messages: 260673 nosy: Ilja Everilä priority: normal severity: normal status: open title: csv.writer.writerows masks exceptions from __iter__ type: behavior _______________________________________ 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