Message238614
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'}) |
|
Date |
User |
Action |
Args |
2015-03-20 07:53:52 | wolma | set | recipients:
+ wolma, georg.brandl, paul.moore, ncoghlan, vstinner, ethan.furman, python-dev, serhiy.storchaka, bkabrda, sYnfo |
2015-03-20 07:53:52 | wolma | set | messageid: <1426838032.77.0.234656200851.issue23700@psf.upfronthosting.co.za> |
2015-03-20 07:53:52 | wolma | link | issue23700 messages |
2015-03-20 07:53:52 | wolma | create | |
|