-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[perflint] implement quick-fix for manual-dict-comprehension (PERF404) #16719
base: main
Are you sure you want to change the base?
Conversation
|
code | total | + violation | - violation | + fix | - fix |
---|---|---|---|---|---|
PERF403 | 12 | 6 | 6 | 0 | 0 |
Linter (preview)
ℹ️ ecosystem check detected linter changes. (+6 -8 violations, +0 -0 fixes in 3 projects; 52 projects unchanged)
apache/airflow (+4 -4 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --preview --select ALL
+ providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/executors/kubernetes_executor_utils.py:143:17: PERF403 Use `dict.update` instead of a for-loop - providers/cncf/kubernetes/src/airflow/providers/cncf/kubernetes/executors/kubernetes_executor_utils.py:143:17: PERF403 Use a dictionary comprehension instead of a for-loop + providers/exasol/src/airflow/providers/exasol/hooks/exasol.py:70:17: PERF403 Use `dict.update` instead of a for-loop - providers/exasol/src/airflow/providers/exasol/hooks/exasol.py:70:17: PERF403 Use a dictionary comprehension instead of a for-loop + providers/mysql/src/airflow/providers/mysql/hooks/mysql.py:191:17: PERF403 Use `dict.update` instead of a for-loop - providers/mysql/src/airflow/providers/mysql/hooks/mysql.py:191:17: PERF403 Use a dictionary comprehension instead of a for-loop + providers/postgres/src/airflow/providers/postgres/hooks/postgres.py:172:17: PERF403 Use `dict.update` instead of a for-loop - providers/postgres/src/airflow/providers/postgres/hooks/postgres.py:172:17: PERF403 Use a dictionary comprehension instead of a for-loop
apache/superset (+2 -2 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --preview --select ALL
+ superset/migrations/versions/2021-04-12_12-38_fc3a3a8ff221_migrate_filter_sets_to_new_format.py:122:21: PERF403 Use `dict.update` instead of a for-loop - superset/migrations/versions/2021-04-12_12-38_fc3a3a8ff221_migrate_filter_sets_to_new_format.py:122:21: PERF403 Use a dictionary comprehension instead of a for-loop + superset/migrations/versions/2022-04-01_14-38_a9422eeaae74_new_dataset_models_take_2.py:795:21: PERF403 Use `dict.update` instead of a for-loop - superset/migrations/versions/2022-04-01_14-38_a9422eeaae74_new_dataset_models_take_2.py:795:21: PERF403 Use a dictionary comprehension instead of a for-loop
pandas-dev/pandas (+0 -2 violations, +0 -0 fixes)
ruff check --no-cache --exit-zero --ignore RUF9 --no-fix --output-format concise --preview
- pandas/tests/arrays/sparse/test_accessor.py:247:30: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw - pandas/tests/arrays/sparse/test_accessor.py:96:50: RUF043 Pattern passed to `match=` contains metacharacters but is neither escaped nor raw
Changes by rule (2 rules affected)
code | total | + violation | - violation | + fix | - fix |
---|---|---|---|---|---|
PERF403 | 12 | 6 | 6 | 0 | 0 |
RUF043 | 2 | 0 | 2 | 0 | 0 |
Slight nit: had a situation where it didn't simplify an node_to_step: dict[BaseSchedulerNode, int] = dict()
for step, node in enumerate(nodes):
node_to_step[node] = step got transformed to node_to_step: dict[BaseSchedulerNode, int] = dict()
node_to_step.update(...) |
I had forgotten about using a function call to make a dict, since it's not typically something I do in my own code. I've now modified the "is empty dict" check to allow builtin function calls for both PERF403 and PERF401. |
merge with main
Summary
This change adds an auto-fix for manual dict comprehensions. It also copies many of the improvements from #13919 (and associated PRs fixing issues with it), and moves some of the utility functions from
manual_list_comprehension.rs
into a separatehelpers.rs
to be used in both.Test Plan
I added a preview test case to showcase the new fix and added a test case in
PERF403.py
to make sure lines with semicolons function. I didn't yet make similar tests to the ones I added earlier toPERF401.py
, but the logic is the same, so it might be good to add those to make sure they work.