astral-sh / ruff

An extremely fast Python linter and code formatter, written in Rust.
https://docs.astral.sh/ruff
MIT License
33k stars 1.1k forks source link

Rule suggestion: Convert list.extend([x]) to list.append(x) #14518

Open NeilGirdhar opened 20 hours ago

NeilGirdhar commented 20 hours ago

This may depend on RedKnot, but with type information, this could hit a lot of code. If we know retval is a list, consider converting:

retval.extend([x]) 

to

retval.append(x)

And similarly, merge

retval.extend([x, y])
retval.append(v)
retval.extend([z, w])

etc.

It may not seem like merging will catch a lot of cases, but having the Ruff action available makes it available in my editor, which is a great convenience.