Skip to content

Conversation

@w0nder1ng
Copy link
Contributor

This is an implementation of the discussion from #16719.

This change will allow list function calls to be replaced with comprehensions:

result = list()
for i in range(3):
    result.append(i + 1)
# becomes
result = [i + 1 for i in range(3)]

I added a new test to PERF401.py to verify that this fix will now work for list().

@github-actions
Copy link
Contributor

ruff-ecosystem results

Linter (stable)

ℹ️ ecosystem check detected linter changes. (+7 -7 violations, +0 -0 fixes in 1 projects; 54 projects unchanged)

apache/superset (+7 -7 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --no-preview --select ALL

- tests/integration_tests/charts/api_tests.py:350:13: PERF401 Use `list.extend` to create a transformed list
+ tests/integration_tests/charts/api_tests.py:350:13: PERF401 Use a list comprehension to create a transformed list
- tests/integration_tests/charts/api_tests.py:464:13: PERF401 Use `list.extend` to create a transformed list
+ tests/integration_tests/charts/api_tests.py:464:13: PERF401 Use a list comprehension to create a transformed list
- tests/integration_tests/charts/api_tests.py:515:13: PERF401 Use `list.extend` to create a transformed list
+ tests/integration_tests/charts/api_tests.py:515:13: PERF401 Use a list comprehension to create a transformed list
- tests/integration_tests/dashboards/api_tests.py:1280:13: PERF401 Use `list.extend` to create a transformed list
+ tests/integration_tests/dashboards/api_tests.py:1280:13: PERF401 Use a list comprehension to create a transformed list
- tests/integration_tests/dashboards/api_tests.py:1307:13: PERF401 Use `list.extend` to create a transformed list
+ tests/integration_tests/dashboards/api_tests.py:1307:13: PERF401 Use a list comprehension to create a transformed list
- tests/integration_tests/dashboards/api_tests.py:1441:13: PERF401 Use `list.extend` to create a transformed list
+ tests/integration_tests/dashboards/api_tests.py:1441:13: PERF401 Use a list comprehension to create a transformed list
- tests/integration_tests/dashboards/api_tests.py:1506:13: PERF401 Use `list.extend` to create a transformed list
+ tests/integration_tests/dashboards/api_tests.py:1506:13: PERF401 Use a list comprehension to create a transformed list

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
PERF401 14 7 7 0 0

Linter (preview)

ℹ️ ecosystem check detected linter changes. (+7 -7 violations, +0 -0 fixes in 1 projects; 54 projects unchanged)

apache/superset (+7 -7 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --preview --select ALL

- tests/integration_tests/charts/api_tests.py:350:13: PERF401 Use `list.extend` to create a transformed list
+ tests/integration_tests/charts/api_tests.py:350:13: PERF401 Use a list comprehension to create a transformed list
- tests/integration_tests/charts/api_tests.py:464:13: PERF401 Use `list.extend` to create a transformed list
+ tests/integration_tests/charts/api_tests.py:464:13: PERF401 Use a list comprehension to create a transformed list
- tests/integration_tests/charts/api_tests.py:515:13: PERF401 Use `list.extend` to create a transformed list
+ tests/integration_tests/charts/api_tests.py:515:13: PERF401 Use a list comprehension to create a transformed list
- tests/integration_tests/dashboards/api_tests.py:1280:13: PERF401 Use `list.extend` to create a transformed list
+ tests/integration_tests/dashboards/api_tests.py:1280:13: PERF401 Use a list comprehension to create a transformed list
- tests/integration_tests/dashboards/api_tests.py:1307:13: PERF401 Use `list.extend` to create a transformed list
+ tests/integration_tests/dashboards/api_tests.py:1307:13: PERF401 Use a list comprehension to create a transformed list
- tests/integration_tests/dashboards/api_tests.py:1441:13: PERF401 Use `list.extend` to create a transformed list
+ tests/integration_tests/dashboards/api_tests.py:1441:13: PERF401 Use a list comprehension to create a transformed list
- tests/integration_tests/dashboards/api_tests.py:1506:13: PERF401 Use `list.extend` to create a transformed list
+ tests/integration_tests/dashboards/api_tests.py:1506:13: PERF401 Use a list comprehension to create a transformed list

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
PERF401 14 7 7 0 0

@dhruvmanila dhruvmanila requested a review from ntBre April 21, 2025 16:49
@ntBre ntBre self-assigned this Apr 21, 2025
Copy link
Contributor

@ntBre ntBre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the follow-up and for the test cases! I don't think this needs to be in preview, as it's just a straightforward extension of the [] case to list().

@ntBre ntBre added the rule Implementing or modifying a lint rule label Apr 21, 2025
@ntBre ntBre merged commit 9c0772d into astral-sh:main Apr 21, 2025
22 checks passed
dcreager added a commit that referenced this pull request Apr 22, 2025
* main: (37 commits)
  [red-knot] Add list of failing/slow ecosystem projects (#17474)
  [red-knot] mypy_primer: extend ecosystem checks (#17544)
  [red-knot] Move `InstanceType` to its own submodule (#17525)
  [red-knot] mypy_primer: capture backtraces (#17543)
  [red-knot] mypy_primer: Use upstream repo (#17500)
  [red-knot] `typing.dataclass_transform` (#17445)
  Update dependency react-resizable-panels to v2.1.8 (#17513)
  Update dependency smol-toml to v1.3.3 (#17505)
  Update dependency uuid to v11.1.0 (#17517)
  Update actions/setup-node action to v4.4.0 (#17514)
  [red-knot] Fix variable name (#17532)
  [red-knot] Add basic subtyping between class literal and callable (#17469)
  [`pyupgrade`] Add fix safety section to docs (`UP030`) (#17443)
  [`perflint`] Allow list function calls to be replaced with a comprehension (`PERF401`) (#17519)
  Update pre-commit dependencies (#17506)
  [red-knot] Simplify visibility constraint handling for `*`-import definitions (#17486)
  [red-knot] Detect (some) invalid protocols (#17488)
  [red-knot] Correctly identify protocol classes (#17487)
  Update dependency ruff to v0.11.6 (#17516)
  Update Rust crate shellexpand to v3.1.1 (#17512)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

rule Implementing or modifying a lint rule

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants