]> granicus.if.org Git - python/commitdiff
Issue #23700: NamedTemporaryFile iterator closed underlied file object in
authorSerhiy Storchaka <storchaka@gmail.com>
Fri, 20 Mar 2015 14:11:20 +0000 (16:11 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Fri, 20 Mar 2015 14:11:20 +0000 (16:11 +0200)
some circunstances while NamedTemporaryFile object was living.  This causes
failing test_csv.  Changed the implementation of NamedTemporaryFile.__iter__
to make tests passed.

Lib/tempfile.py

index 8352c38a0d7362d17015ac8b82159572d6cbc235..cb18ae65f603033e0eaddd092f6b28d56dab3514 100644 (file)
@@ -426,9 +426,11 @@ class _TemporaryFileWrapper:
 
     # iter() doesn't use __getattr__ to find the __iter__ method
     def __iter__(self):
-        # don't return iter(self.file), but yield from it to avoid closing
-        # file as long as it's being used as iterator, see issue #23000
-        yield from iter(self.file)
+        # Don't return iter(self.file), but yield from it to avoid closing
+        # file as long as it's being used as iterator, see issue #23000.
+        # XXX Also don't use "yield from"!
+        for line in self.file:
+            yield line
 
 
 def NamedTemporaryFile(mode='w+b', buffering=-1, encoding=None,