This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author wolma
Recipients bkabrda, ethan.furman, georg.brandl, ncoghlan, paul.moore, python-dev, sYnfo, serhiy.storchaka, vstinner, wolma
Date 2015-03-20.07:53:52
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1426838032.77.0.234656200851.issue23700@psf.upfronthosting.co.za>
In-reply-to
Content
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'})
History
Date User Action Args
2015-03-20 07:53:52wolmasetrecipients: + wolma, georg.brandl, paul.moore, ncoghlan, vstinner, ethan.furman, python-dev, serhiy.storchaka, bkabrda, sYnfo
2015-03-20 07:53:52wolmasetmessageid: <1426838032.77.0.234656200851.issue23700@psf.upfronthosting.co.za>
2015-03-20 07:53:52wolmalinkissue23700 messages
2015-03-20 07:53:52wolmacreate