Skip to content

PERF402 slightly incorrect fix suggestion #8070

@Skylion007

Description

@Skylion007
a = []
for i in range(10):
    for j in range(100):
        a.append(j)

ruff version 0.1.0

This rule outputs
test-perf.py:4:9: PERF402 Use `list` or `list.copy` to create a copy of a list
Which while correct in that something should be done here, it really should be calling .extend() not the list or list.copy() constructor. Doing

a = []
for i in range(10):
    a = list(range(100))

would yield an invalid result.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions