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 <>
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:
            reader = csv.DictReader(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:52wolmasetrecipients: + wolma, georg.brandl, paul.moore, ncoghlan, vstinner, ethan.furman, python-dev, serhiy.storchaka, bkabrda, sYnfo
2015-03-20 07:53:52wolmasetmessageid: <>
2015-03-20 07:53:52wolmalinkissue23700 messages
2015-03-20 07:53:52wolmacreate