[perflint] implement quick-fix for manual-list-comprehension (PERF401) (#13919)

Co-authored-by: Micha Reiser <micha@reiser.io>
This commit is contained in:
w0nder1ng 2024-11-11 06:17:02 -05:00 committed by GitHub
parent 813ec23ecd
commit 5a3886c8b5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 491 additions and 10 deletions

View file

@ -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)