Wolfgang Maier added the comment: I think this is a consequence of PEP380 and its decision to finalize the subgenerator when the delegating generator is closed. Consider this simple example without tempfile:
def yielder (fileobj): yield from fileobj with open('some_test_file', 'w') as f: f.write('line one\nline two\nline three') with open('some_test_file', 'r') as f: line = next(yielder(f)) nline = next(f) ==> Traceback (most recent call last): File "<pyshell#11>", line 3, in <module> nline = next(f) ValueError: I/O operation on closed file. I think test_csv does the file-closing operation on lines 626/627 when it creates the temporary csv.reader(fileobj). def test_read_dict_fieldnames_from_file(self): with TemporaryFile("w+") as fileobj: fileobj.write("f1,f2,f3\r\n1,2,abc\r\n") fileobj.seek(0) reader = csv.DictReader(fileobj, fieldnames=next(csv.reader(fileobj))) self.assertEqual(reader.fieldnames, ["f1", "f2", "f3"]) self.assertEqual(next(reader), {"f1": '1', "f2": '2', "f3": 'abc'}) ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue23700> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com