mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 18:58:04 +00:00
[perflint
] implement quick-fix for manual-list-comprehension
(PERF401
) (#13919)
Co-authored-by: Micha Reiser <micha@reiser.io>
This commit is contained in:
parent
813ec23ecd
commit
5a3886c8b5
5 changed files with 491 additions and 10 deletions
|
@ -87,3 +87,41 @@ def f():
|
|||
result = []
|
||||
async for i in items:
|
||||
result.append(i) # PERF401
|
||||
|
||||
|
||||
def f():
|
||||
result, _ = [1,2,3,4], ...
|
||||
for i in range(10):
|
||||
result.append(i*2) # PERF401
|
||||
|
||||
|
||||
def f():
|
||||
result = []
|
||||
if True:
|
||||
for i in range(10): # single-line comment 1 should be protected
|
||||
# single-line comment 2 should be protected
|
||||
if i % 2: # single-line comment 3 should be protected
|
||||
result.append(i) # PERF401
|
||||
|
||||
|
||||
def f():
|
||||
result = [] # comment after assignment should be protected
|
||||
for i in range(10): # single-line comment 1 should be protected
|
||||
# single-line comment 2 should be protected
|
||||
if i % 2: # single-line comment 3 should be protected
|
||||
result.append(i) # PERF401
|
||||
|
||||
|
||||
def f():
|
||||
result = []
|
||||
for i in range(10):
|
||||
"""block comment stops the fix"""
|
||||
result.append(i*2) # Ok
|
||||
|
||||
def f(param):
|
||||
# PERF401
|
||||
# make sure the fix does not panic if there is no comments
|
||||
if param:
|
||||
new_layers = []
|
||||
for value in param:
|
||||
new_layers.append(value * 3)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue