Skip to content

SpooledTemporaryFile.__iter__ is not transparent to rollover #87034

Description

@jinohkangkr
BPO 42868

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = None
created_at = <Date 2021-01-08.14:46:35.069>
labels = ['type-bug', 'library', '3.10']
title = 'SpooledTemporaryFile.__iter__ is not transparent to rollover'
updated_at = <Date 2021-01-08.14:46:35.069>
user = 'https://bugs.python.org/jinohkangkr'

bugs.python.org fields:

activity = <Date 2021-01-08.14:46:35.069>
actor = 'jinoh.kang.kr'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Library (Lib)']
creation = <Date 2021-01-08.14:46:35.069>
creator = 'jinoh.kang.kr'
dependencies = []
files = []
hgrepos = []
issue_num = 42868
keywords = []
message_count = 1.0
messages = ['384674']
nosy_count = 1.0
nosy_names = ['jinoh.kang.kr']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue42868'
versions = ['Python 3.10']

Linked PRs

Activity

  1. jinohkangkr commented on Jan 8, 2021

    jinohkangkrmannequin
    MannequinAuthor

    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
  2. added
    stdlibStandard Library Python modules in the Lib/ directory
    type-bugAn unexpected behavior, bug, or error
    on Jan 8, 2021
  3. transferred this issue fromon Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.10 (EOL)end of lifestdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions