Skip to content

detect infinite list extend/append #103284

Closed as not planned
Closed as not planned
@fpom

Description

@fpom

When the size of a dict changes while it is iterated over, we get a RuntimeError. But this is not the case on lists. For instance, the following code will loop until it exhausts memory:

seq = list(range(10))
for s in seq:
    seq.append(s)

Same situation with this code:

seq = list(range(10))
seq.extend(s for s in seq)

I would have expected such a corner case to be detected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions