Skip to content
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

Improve error messages and docs for flake8-comprehensions rules #14729

Merged
merged 1 commit into from
Dec 2, 2024

Conversation

AlexWaygood
Copy link
Member

Summary

This PR attempts to improve the docs and error messages for our flake8-comprehension rules. Along the way I saw various opportunities for cleanups and micro-optimisations, but the only significant changes should be to the error messages and docs.

The main change is to remove quite a few backticks which don't seem necessary and, I think, contributed to some of the confusion in #14644. For example, rather than referring to "set comprehensions", refer to "set comprehensions". This reads more naturally, and it's harder to misunderstand it as saying "use a call to set()", which is how it was misread by the OP in #14644.

Test Plan

cargo test -p ruff_linter --lib

@AlexWaygood AlexWaygood added the documentation Improvements or additions to documentation label Dec 2, 2024
Copy link
Contributor

github-actions bot commented Dec 2, 2024

ruff-ecosystem results

Linter (stable)

ℹ️ ecosystem check detected linter changes. (+3239 -3239 violations, +0 -0 fixes in 6 projects; 49 projects unchanged)

apache/airflow (+928 -928 violations, +0 -0 fixes)

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

+ airflow/api_connexion/endpoints/dag_stats_endpoint.py:58:21: C414 Unnecessary `list()` call within `sorted()`
- airflow/api_connexion/endpoints/dag_stats_endpoint.py:58:21: C414 Unnecessary `list` call within `sorted()`
- airflow/api_fastapi/core_api/routes/public/dags.py:139:42: C416 Unnecessary `list` comprehension (rewrite using `list()`)
+ airflow/api_fastapi/core_api/routes/public/dags.py:139:42: C416 Unnecessary list comprehension (rewrite using `list()`)
- airflow/api_fastapi/core_api/routes/ui/config.py:69:19: C416 Unnecessary `dict` comprehension (rewrite using `dict()`)
+ airflow/api_fastapi/core_api/routes/ui/config.py:69:19: C416 Unnecessary dict comprehension (rewrite using `dict()`)
+ airflow/cli/commands/backfill_command.py:65:20: C408 Unnecessary `dict()` call (rewrite as a literal)
- airflow/cli/commands/backfill_command.py:65:20: C408 Unnecessary `dict` call (rewrite as a literal)
+ airflow/cli/commands/variable_command.py:113:47: C413 [*] Unnecessary `list()` call around `sorted()`
- airflow/cli/commands/variable_command.py:113:47: C413 [*] Unnecessary `list` call around `sorted()`
- airflow/dag_processing/collection.py:481:34: C416 Unnecessary `list` comprehension (rewrite using `list()`)
+ airflow/dag_processing/collection.py:481:34: C416 Unnecessary list comprehension (rewrite using `list()`)
... 31 additional changes omitted for rule C416
- airflow/dag_processing/manager.py:1370:26: C400 Unnecessary generator (rewrite as a `list` comprehension)
+ airflow/dag_processing/manager.py:1370:26: C400 Unnecessary generator (rewrite as a list comprehension)
... 1842 additional changes omitted for project

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

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

+ superset/advanced_data_type/plugins/internet_address.py:68:17: C417 Unnecessary `map()` usage (rewrite using a generator expression)
- superset/advanced_data_type/plugins/internet_address.py:68:17: C417 Unnecessary `map` usage (rewrite using a generator expression)
+ superset/advanced_data_type/plugins/internet_port.py:97:17: C417 Unnecessary `map()` usage (rewrite using a generator expression)
- superset/advanced_data_type/plugins/internet_port.py:97:17: C417 Unnecessary `map` usage (rewrite using a generator expression)
- superset/charts/post_processing.py:175:33: C409 Unnecessary `list` literal passed to `tuple()` (rewrite as a `tuple` literal)
+ superset/charts/post_processing.py:175:33: C409 Unnecessary list literal passed to `tuple()` (rewrite as a tuple literal)
- superset/charts/post_processing.py:192:33: C409 Unnecessary `list` literal passed to `tuple()` (rewrite as a `tuple` literal)
+ superset/charts/post_processing.py:192:33: C409 Unnecessary list literal passed to `tuple()` (rewrite as a tuple literal)
+ superset/commands/exceptions.py:74:16: C413 [*] Unnecessary `list()` call around `sorted()`
- superset/commands/exceptions.py:74:16: C413 [*] Unnecessary `list` call around `sorted()`
... 180 additional changes omitted for project

bokeh/bokeh (+948 -948 violations, +0 -0 fixes)

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

+ docs/bokeh/source/docs/first_steps/examples/first_steps_8_filter.py:6:32: C408 Unnecessary `dict()` call (rewrite as a literal)
- docs/bokeh/source/docs/first_steps/examples/first_steps_8_filter.py:6:32: C408 Unnecessary `dict` call (rewrite as a literal)
+ examples/advanced/extensions/parallel_plot/parallel_plot.py:29:36: C408 Unnecessary `dict()` call (rewrite as a literal)
- examples/advanced/extensions/parallel_plot/parallel_plot.py:29:36: C408 Unnecessary `dict` call (rewrite as a literal)
+ examples/advanced/extensions/parallel_plot/parallel_plot.py:72:31: C408 Unnecessary `dict()` call (rewrite as a literal)
- examples/advanced/extensions/parallel_plot/parallel_plot.py:72:31: C408 Unnecessary `dict` call (rewrite as a literal)
... 1857 additional changes omitted for rule C408
+ examples/basic/annotations/whisker.py:17:11: C413 [*] Unnecessary `list()` call around `sorted()`
- examples/basic/annotations/whisker.py:17:11: C413 [*] Unnecessary `list` call around `sorted()`
- examples/output/webgl/clustering.py:24:19: C416 Unnecessary `list` comprehension (rewrite using `list()`)
+ examples/output/webgl/clustering.py:24:19: C416 Unnecessary list comprehension (rewrite using `list()`)
- examples/plotting/filtering.py:47:30: C416 Unnecessary `list` comprehension (rewrite using `list()`)
+ examples/plotting/filtering.py:47:30: C416 Unnecessary list comprehension (rewrite using `list()`)
- examples/topics/pie/burtin.py:25:8: C406 Unnecessary `list` literal (rewrite as a `dict` literal)
+ examples/topics/pie/burtin.py:25:8: C406 Unnecessary list literal (rewrite as a dict literal)
... 1882 additional changes omitted for project

latchbio/latch (+11 -11 violations, +0 -0 fixes)

- src/latch/account.py:274:25: C409 Unnecessary `list` literal passed to `tuple()` (rewrite as a `tuple` literal)
+ src/latch/account.py:274:25: C409 Unnecessary list literal passed to `tuple()` (rewrite as a tuple literal)
- src/latch/account.py:312:25: C409 Unnecessary `list` literal passed to `tuple()` (rewrite as a `tuple` literal)
+ src/latch/account.py:312:25: C409 Unnecessary list literal passed to `tuple()` (rewrite as a tuple literal)
- src/latch/ldata/_transfer/progress.py:48:29: C416 Unnecessary `set` comprehension (rewrite using `set()`)
+ src/latch/ldata/_transfer/progress.py:48:29: C416 Unnecessary set comprehension (rewrite using `set()`)
- src/latch/registry/project.py:245:25: C409 Unnecessary `list` literal passed to `tuple()` (rewrite as a `tuple` literal)
+ src/latch/registry/project.py:245:25: C409 Unnecessary list literal passed to `tuple()` (rewrite as a tuple literal)
... 9 additional changes omitted for rule C409
- src/latch/registry/table.py:637:27: C400 Unnecessary generator (rewrite as a `list` comprehension)
+ src/latch/registry/table.py:637:27: C400 Unnecessary generator (rewrite as a list comprehension)
... 12 additional changes omitted for project

milvus-io/pymilvus (+24 -24 violations, +0 -0 fixes)

- examples/bulk_import/example_bulkwriter.py:101:33: C416 Unnecessary `list` comprehension (rewrite using `list()`)
+ examples/bulk_import/example_bulkwriter.py:101:33: C416 Unnecessary list comprehension (rewrite using `list()`)
- examples/bulk_import/example_bulkwriter.py:314:30: C416 Unnecessary `list` comprehension (rewrite using `list()`)
+ examples/bulk_import/example_bulkwriter.py:314:30: C416 Unnecessary list comprehension (rewrite using `list()`)
- examples/bulk_import/example_bulkwriter.py:341:39: C416 Unnecessary `list` comprehension (rewrite using `list()`)
+ examples/bulk_import/example_bulkwriter.py:341:39: C416 Unnecessary list comprehension (rewrite using `list()`)
- examples/concurrency/multithreading_hello_milvus.py:42:23: C416 Unnecessary `list` comprehension (rewrite using `list()`)
+ examples/concurrency/multithreading_hello_milvus.py:42:23: C416 Unnecessary list comprehension (rewrite using `list()`)
- examples/concurrency/multithreading_hello_milvus.py:53:13: C416 Unnecessary `list` comprehension (rewrite using `list()`)
+ examples/concurrency/multithreading_hello_milvus.py:53:13: C416 Unnecessary list comprehension (rewrite using `list()`)
... 38 additional changes omitted for project

zulip/zulip (+1233 -1233 violations, +0 -0 fixes)

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

+ analytics/migrations/0015_clear_duplicate_counts.py:23:20: C408 Unnecessary `dict()` call (rewrite as a literal)
- analytics/migrations/0015_clear_duplicate_counts.py:23:20: C408 Unnecessary `dict` call (rewrite as a literal)
+ analytics/views/stats.py:83:19: C408 Unnecessary `dict()` call (rewrite as a literal)
- analytics/views/stats.py:83:19: C408 Unnecessary `dict` call (rewrite as a literal)
+ analytics/views/stats.py:94:17: C408 Unnecessary `dict()` call (rewrite as a literal)
- analytics/views/stats.py:94:17: C408 Unnecessary `dict` call (rewrite as a literal)
+ corporate/lib/activity.py:122:45: C408 Unnecessary `dict()` call (rewrite as a literal)
- corporate/lib/activity.py:122:45: C408 Unnecessary `dict` call (rewrite as a literal)
+ corporate/lib/activity.py:129:46: C408 Unnecessary `dict()` call (rewrite as a literal)
- corporate/lib/activity.py:129:46: C408 Unnecessary `dict` call (rewrite as a literal)
+ corporate/lib/activity.py:136:43: C408 Unnecessary `dict()` call (rewrite as a literal)
- corporate/lib/activity.py:136:43: C408 Unnecessary `dict` call (rewrite as a literal)
+ corporate/lib/activity.py:163:57: C408 Unnecessary `dict()` call (rewrite as a literal)
- corporate/lib/activity.py:163:57: C408 Unnecessary `dict` call (rewrite as a literal)
+ corporate/lib/activity.py:59:20: C408 Unnecessary `dict()` call (rewrite as a literal)
- corporate/lib/activity.py:59:20: C408 Unnecessary `dict` call (rewrite as a literal)
+ corporate/lib/activity.py:63:12: C408 Unnecessary `dict()` call (rewrite as a literal)
- corporate/lib/activity.py:63:12: C408 Unnecessary `dict` call (rewrite as a literal)
+ corporate/lib/activity.py:69:9: C408 Unnecessary `dict()` call (rewrite as a literal)
... 2447 additional changes omitted for project

Changes by rule (13 rules affected)

code total + violation - violation + fix - fix
C408 6062 3031 3031 0 0
C416 126 63 63 0 0
C403 60 30 30 0 0
C401 58 29 29 0 0
C417 40 20 20 0 0
C400 36 18 18 0 0
C414 30 15 15 0 0
C409 30 15 15 0 0
C413 12 6 6 0 0
C418 12 6 6 0 0
C405 4 2 2 0 0
C402 4 2 2 0 0
C406 4 2 2 0 0

Linter (preview)

ℹ️ ecosystem check detected linter changes. (+3239 -3239 violations, +0 -0 fixes in 6 projects; 49 projects unchanged)

apache/airflow (+928 -928 violations, +0 -0 fixes)

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

+ airflow/api_connexion/endpoints/dag_stats_endpoint.py:58:21: C414 Unnecessary `list()` call within `sorted()`
- airflow/api_connexion/endpoints/dag_stats_endpoint.py:58:21: C414 Unnecessary `list` call within `sorted()`
- airflow/api_fastapi/core_api/routes/public/dags.py:139:42: C416 Unnecessary `list` comprehension (rewrite using `list()`)
+ airflow/api_fastapi/core_api/routes/public/dags.py:139:42: C416 Unnecessary list comprehension (rewrite using `list()`)
- airflow/api_fastapi/core_api/routes/ui/config.py:69:19: C416 Unnecessary `dict` comprehension (rewrite using `dict()`)
+ airflow/api_fastapi/core_api/routes/ui/config.py:69:19: C416 Unnecessary dict comprehension (rewrite using `dict()`)
+ airflow/cli/commands/backfill_command.py:65:20: C408 Unnecessary `dict()` call (rewrite as a literal)
- airflow/cli/commands/backfill_command.py:65:20: C408 Unnecessary `dict` call (rewrite as a literal)
+ airflow/cli/commands/variable_command.py:113:47: C413 [*] Unnecessary `list()` call around `sorted()`
- airflow/cli/commands/variable_command.py:113:47: C413 [*] Unnecessary `list` call around `sorted()`
- airflow/dag_processing/collection.py:481:34: C416 Unnecessary `list` comprehension (rewrite using `list()`)
+ airflow/dag_processing/collection.py:481:34: C416 Unnecessary list comprehension (rewrite using `list()`)
... 31 additional changes omitted for rule C416
- airflow/dag_processing/manager.py:1370:26: C400 Unnecessary generator (rewrite as a `list` comprehension)
+ airflow/dag_processing/manager.py:1370:26: C400 Unnecessary generator (rewrite as a list comprehension)
... 1842 additional changes omitted for project

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

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

+ superset/advanced_data_type/plugins/internet_address.py:68:17: C417 Unnecessary `map()` usage (rewrite using a generator expression)
- superset/advanced_data_type/plugins/internet_address.py:68:17: C417 Unnecessary `map` usage (rewrite using a generator expression)
+ superset/advanced_data_type/plugins/internet_port.py:97:17: C417 Unnecessary `map()` usage (rewrite using a generator expression)
- superset/advanced_data_type/plugins/internet_port.py:97:17: C417 Unnecessary `map` usage (rewrite using a generator expression)
- superset/charts/post_processing.py:175:33: C409 Unnecessary `list` literal passed to `tuple()` (rewrite as a `tuple` literal)
+ superset/charts/post_processing.py:175:33: C409 Unnecessary list literal passed to `tuple()` (rewrite as a tuple literal)
- superset/charts/post_processing.py:192:33: C409 Unnecessary `list` literal passed to `tuple()` (rewrite as a `tuple` literal)
+ superset/charts/post_processing.py:192:33: C409 Unnecessary list literal passed to `tuple()` (rewrite as a tuple literal)
+ superset/commands/exceptions.py:74:16: C413 [*] Unnecessary `list()` call around `sorted()`
- superset/commands/exceptions.py:74:16: C413 [*] Unnecessary `list` call around `sorted()`
... 180 additional changes omitted for project

bokeh/bokeh (+948 -948 violations, +0 -0 fixes)

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

+ docs/bokeh/source/docs/first_steps/examples/first_steps_8_filter.py:6:32: C408 Unnecessary `dict()` call (rewrite as a literal)
- docs/bokeh/source/docs/first_steps/examples/first_steps_8_filter.py:6:32: C408 Unnecessary `dict` call (rewrite as a literal)
+ examples/advanced/extensions/parallel_plot/parallel_plot.py:29:36: C408 Unnecessary `dict()` call (rewrite as a literal)
- examples/advanced/extensions/parallel_plot/parallel_plot.py:29:36: C408 Unnecessary `dict` call (rewrite as a literal)
+ examples/advanced/extensions/parallel_plot/parallel_plot.py:72:31: C408 Unnecessary `dict()` call (rewrite as a literal)
- examples/advanced/extensions/parallel_plot/parallel_plot.py:72:31: C408 Unnecessary `dict` call (rewrite as a literal)
... 1857 additional changes omitted for rule C408
+ examples/basic/annotations/whisker.py:17:11: C413 [*] Unnecessary `list()` call around `sorted()`
- examples/basic/annotations/whisker.py:17:11: C413 [*] Unnecessary `list` call around `sorted()`
- examples/output/webgl/clustering.py:24:19: C416 Unnecessary `list` comprehension (rewrite using `list()`)
+ examples/output/webgl/clustering.py:24:19: C416 Unnecessary list comprehension (rewrite using `list()`)
- examples/plotting/filtering.py:47:30: C416 Unnecessary `list` comprehension (rewrite using `list()`)
+ examples/plotting/filtering.py:47:30: C416 Unnecessary list comprehension (rewrite using `list()`)
- examples/topics/pie/burtin.py:25:8: C406 Unnecessary `list` literal (rewrite as a `dict` literal)
+ examples/topics/pie/burtin.py:25:8: C406 Unnecessary list literal (rewrite as a dict literal)
... 1882 additional changes omitted for project

latchbio/latch (+11 -11 violations, +0 -0 fixes)

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

- src/latch/account.py:274:25: C409 Unnecessary `list` literal passed to `tuple()` (rewrite as a `tuple` literal)
+ src/latch/account.py:274:25: C409 Unnecessary list literal passed to `tuple()` (rewrite as a tuple literal)
- src/latch/account.py:312:25: C409 Unnecessary `list` literal passed to `tuple()` (rewrite as a `tuple` literal)
+ src/latch/account.py:312:25: C409 Unnecessary list literal passed to `tuple()` (rewrite as a tuple literal)
- src/latch/ldata/_transfer/progress.py:48:29: C416 Unnecessary `set` comprehension (rewrite using `set()`)
+ src/latch/ldata/_transfer/progress.py:48:29: C416 Unnecessary set comprehension (rewrite using `set()`)
- src/latch/registry/project.py:245:25: C409 Unnecessary `list` literal passed to `tuple()` (rewrite as a `tuple` literal)
+ src/latch/registry/project.py:245:25: C409 Unnecessary list literal passed to `tuple()` (rewrite as a tuple literal)
... 9 additional changes omitted for rule C409
- src/latch/registry/table.py:637:27: C400 Unnecessary generator (rewrite as a `list` comprehension)
+ src/latch/registry/table.py:637:27: C400 Unnecessary generator (rewrite as a list comprehension)
... 12 additional changes omitted for project

milvus-io/pymilvus (+24 -24 violations, +0 -0 fixes)

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

- examples/bulk_import/example_bulkwriter.py:101:33: C416 Unnecessary `list` comprehension (rewrite using `list()`)
+ examples/bulk_import/example_bulkwriter.py:101:33: C416 Unnecessary list comprehension (rewrite using `list()`)
- examples/bulk_import/example_bulkwriter.py:314:30: C416 Unnecessary `list` comprehension (rewrite using `list()`)
+ examples/bulk_import/example_bulkwriter.py:314:30: C416 Unnecessary list comprehension (rewrite using `list()`)
- examples/bulk_import/example_bulkwriter.py:341:39: C416 Unnecessary `list` comprehension (rewrite using `list()`)
+ examples/bulk_import/example_bulkwriter.py:341:39: C416 Unnecessary list comprehension (rewrite using `list()`)
- examples/concurrency/multithreading_hello_milvus.py:42:23: C416 Unnecessary `list` comprehension (rewrite using `list()`)
+ examples/concurrency/multithreading_hello_milvus.py:42:23: C416 Unnecessary list comprehension (rewrite using `list()`)
- examples/concurrency/multithreading_hello_milvus.py:53:13: C416 Unnecessary `list` comprehension (rewrite using `list()`)
+ examples/concurrency/multithreading_hello_milvus.py:53:13: C416 Unnecessary list comprehension (rewrite using `list()`)
... 38 additional changes omitted for project

zulip/zulip (+1233 -1233 violations, +0 -0 fixes)

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

+ analytics/migrations/0015_clear_duplicate_counts.py:23:20: C408 Unnecessary `dict()` call (rewrite as a literal)
- analytics/migrations/0015_clear_duplicate_counts.py:23:20: C408 Unnecessary `dict` call (rewrite as a literal)
+ analytics/views/stats.py:83:19: C408 Unnecessary `dict()` call (rewrite as a literal)
- analytics/views/stats.py:83:19: C408 Unnecessary `dict` call (rewrite as a literal)
+ analytics/views/stats.py:94:17: C408 Unnecessary `dict()` call (rewrite as a literal)
- analytics/views/stats.py:94:17: C408 Unnecessary `dict` call (rewrite as a literal)
+ corporate/lib/activity.py:122:45: C408 Unnecessary `dict()` call (rewrite as a literal)
- corporate/lib/activity.py:122:45: C408 Unnecessary `dict` call (rewrite as a literal)
+ corporate/lib/activity.py:129:46: C408 Unnecessary `dict()` call (rewrite as a literal)
- corporate/lib/activity.py:129:46: C408 Unnecessary `dict` call (rewrite as a literal)
+ corporate/lib/activity.py:136:43: C408 Unnecessary `dict()` call (rewrite as a literal)
- corporate/lib/activity.py:136:43: C408 Unnecessary `dict` call (rewrite as a literal)
+ corporate/lib/activity.py:163:57: C408 Unnecessary `dict()` call (rewrite as a literal)
- corporate/lib/activity.py:163:57: C408 Unnecessary `dict` call (rewrite as a literal)
+ corporate/lib/activity.py:59:20: C408 Unnecessary `dict()` call (rewrite as a literal)
- corporate/lib/activity.py:59:20: C408 Unnecessary `dict` call (rewrite as a literal)
+ corporate/lib/activity.py:63:12: C408 Unnecessary `dict()` call (rewrite as a literal)
- corporate/lib/activity.py:63:12: C408 Unnecessary `dict` call (rewrite as a literal)
+ corporate/lib/activity.py:69:9: C408 Unnecessary `dict()` call (rewrite as a literal)
... 2447 additional changes omitted for project

Changes by rule (13 rules affected)

code total + violation - violation + fix - fix
C408 6062 3031 3031 0 0
C416 126 63 63 0 0
C403 60 30 30 0 0
C401 58 29 29 0 0
C417 40 20 20 0 0
C400 36 18 18 0 0
C414 30 15 15 0 0
C409 30 15 15 0 0
C413 12 6 6 0 0
C418 12 6 6 0 0
C405 4 2 2 0 0
C402 4 2 2 0 0
C406 4 2 2 0 0

@AlexWaygood
Copy link
Member Author

No changes in the errors being emitted in the ecosystem check, only in the error messages

@AlexWaygood AlexWaygood merged commit 6dfe125 into main Dec 2, 2024
21 checks passed
@AlexWaygood AlexWaygood deleted the alex/comp-docs branch December 2, 2024 13:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant