New submission from Jin-oh Kang <[email protected]>:
In tempfile, SpooledTemporaryFile.__iter__ is defined as follows:
# file protocol
def __iter__(self):
return self._file.__iter__()
A rollover would switch the underlying _file object from a BytesIO to a
TemporaryFile, thereby leaving the original iterator stale.
This may be fixed by:
def __iter__(self):
while True:
line = self._file.readline()
if not line:
break
yield line
Or perhaps:
def __iter__(self):
while True:
file = self._file
for line in file:
yield line
if file is not self._file:
break
else:
break
----------
components: Library (Lib)
messages: 384674
nosy: jinoh.kang.kr
priority: normal
severity: normal
status: open
title: SpooledTemporaryFile.__iter__ is not transparent to rollover
type: behavior
versions: Python 3.10
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue42868>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com