Skip to content

Drop a few rules from the preview default set#23879

Merged
ntBre merged 7 commits intomainfrom
brent/default-rules-update
Mar 11, 2026
Merged

Drop a few rules from the preview default set#23879
ntBre merged 7 commits intomainfrom
brent/default-rules-update

Conversation

@ntBre
Copy link
Copy Markdown
Contributor

@ntBre ntBre commented Mar 10, 2026

Summary

This PR incorporates some feedback from internal discussions on Discord and
from #23203 into the preview default rule set. In particular, we drop:

A couple of these disagree a bit with Clippy's own categorization. For example, RET504 is
let_and_return, which is a Style lint for Clippy. But if users find
it annoying in Python, it makes sense to me to bump it down to Pedantic.

PERF401 and PERF403 also have open issues (#21890, #21891), so I think it makes
sense to consider them lower severity, at least until those are resolved.

TRY300 and PLR1714 are just a bit more pedantic than expected and some people
prefer the styles they flag.

Test Plan

Future default users

ntBre added 6 commits March 10, 2026 12:18
Summary
--

This PR incorporates some feedback from internal discussions on [Discord] and
from #23203 into the preview
default rule set. In particular, we drop:

- [`PERF401`](https://docs.astral.sh/ruff/rules/PERF401)
- [`PERF403`](https://docs.astral.sh/ruff/rules/PERF403)
- [`PLR1714`](https://docs.astral.sh/ruff/rules/PLR1714)
- [`RET504`](https://docs.astral.sh/ruff/rules/RET504)
- [`SIM102`](https://docs.astral.sh/ruff/rules/SIM102)
- [`SIM114`](https://docs.astral.sh/ruff/rules/SIM114)
- [`TRY300`](https://docs.astral.sh/ruff/rules/TRY300)

A couple of these disagree a bit with Clippy's own categorization. For example,
our SIM102 is [collapsible_if], SIM114 is [if_same_then_else], and RET504 is
[let_and_return], all of which are Style lints for Clippy. But if users find
them annoying in Python, it makes sense to me to bump them down to Pedantic.

PERF401 and PERF403 also have open issues (#21890, #21891), so I think it makes
sense to consider them lower severity, at least until those are resolved.

TRY300 and PLR1714 are just a bit more pedantic than expected and some people
prefer the styles they flag.

[Discord]: https://discord.com/channels/1039017663004942429/1082324250112823306/1478345981916348526
[let_and_return]: https://rust-lang.github.io/rust-clippy/master/?search=assign#let_and_return
[collapsible_if]: https://rust-lang.github.io/rust-clippy/master/?search=collap#collapsible_if
[if_same_then_else]: https://rust-lang.github.io/rust-clippy/master/?search=then_#if_same_then_else

Test Plan
--

Future default users
this came up both internally and in the discussion, and it feels similar in
spirit to SIM114
these are a bit controversial and also have open issues, especially around the
`extend` parts:

- #21891
- #21890
@ntBre ntBre added preview Related to preview mode features rule-selection Related to enabling or disabling rules labels Mar 10, 2026
@astral-sh-bot astral-sh-bot bot requested a review from amyreese March 10, 2026 16:19
@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot bot commented Mar 10, 2026

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

ℹ️ ecosystem check detected linter changes. (+0 -723 violations, +0 -0 fixes in 12 projects; 44 projects unchanged)

aiven/aiven-client (+0 -1 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --no-fix --output-format concise --preview

- aiven/client/cli.py:79:17: PERF401 Use a list comprehension to create a transformed list

docker/docker-py (+0 -12 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --no-fix --output-format concise --preview

- docker/api/client.py:296:21: PERF403 Use `dict.update` instead of a for-loop
- docker/auth.py:263:13: TRY300 Consider moving this statement to an `else` block
- docker/auth.py:358:17: PERF401 Use `list.extend` to create a transformed list
- docker/context/api.py:124:13: PERF401 Use `list.extend` to create a transformed list
- docker/models/containers.py:53:13: TRY300 Consider moving this statement to an `else` block
- docker/models/containers.py:892:12: PLR1714 Consider merging multiple comparisons: `logging_driver in {'json-file', 'journald'}`.
- docker/utils/json_stream.py:30:9: TRY300 Consider moving this statement to an `else` block
- docker/utils/utils.py:254:8: PLR1714 Consider merging multiple comparisons: `proto in {'http', 'https'}`.
- tests/integration/api_build_test.py:391:13: PERF401 Use a list comprehension to create a transformed list
- tests/integration/api_volume_test.py:27:17: PLR1714 Consider merging multiple comparisons: `cm.value.response.status_code in {404, 400}`.
... 2 additional changes omitted for project

facebookresearch/chameleon (+0 -10 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --no-fix --output-format concise --preview

- chameleon/inference/logits_processor.py:54:16: RET504 Unnecessary assignment to `probs` before `return` statement
- chameleon/inference/vqgan.py:444:16: RET504 Unnecessary assignment to `h` before `return` statement
- chameleon/inference/vqgan.py:633:16: RET504 Unnecessary assignment to `dec` before `return` statement
- chameleon/inference/vqgan.py:638:16: RET504 Unnecessary assignment to `dec` before `return` statement
- chameleon/inference/vqgan.py:675:16: RET504 Unnecessary assignment to `x` before `return` statement
- chameleon/viewer/backend/models/chameleon_local.py:154:17: PERF401 Use `list.extend` to create a transformed list
- chameleon/viewer/backend/models/chameleon_local.py:321:17: PERF401 Use `list.extend` to create a transformed list
- chameleon/viewer/backend/models/chameleon_local.py:368:17: PERF401 Use `list.extend` to create a transformed list
- chameleon/viewer/backend/models/chameleon_local.py:534:13: PERF401 Use a list comprehension to create a transformed list
- chameleon/viewer/backend/utils.py:28:12: RET504 Unnecessary assignment to `logger` before `return` statement
... 1 additional changes omitted for rule RET504

ing-bank/probatus (+0 -15 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --no-fix --output-format concise --preview

- probatus/feature_elimination/feature_elimination.py:1018:16: RET504 Unnecessary assignment to `ranking` before `return` statement
- probatus/feature_elimination/feature_elimination.py:991:16: RET504 Unnecessary assignment to `support` before `return` statement
- probatus/utils/arrayfuncs.py:155:12: RET504 Unnecessary assignment to `y` before `return` statement
- probatus/utils/shap_helpers.py:203:12: RET504 Unnecessary assignment to `importance_df` before `return` statement
- tests/conftest.py:107:12: RET504 Unnecessary assignment to `model` before `return` statement
- tests/conftest.py:113:12: RET504 Unnecessary assignment to `model` before `return` statement
- tests/conftest.py:120:12: RET504 Unnecessary assignment to `cv` before `return` statement
- tests/conftest.py:126:12: RET504 Unnecessary assignment to `model` before `return` statement
- tests/conftest.py:19:12: RET504 Unnecessary assignment to `RANDOM_STATE` before `return` statement
- tests/conftest.py:26:12: RET504 Unnecessary assignment to `RANDOM_STATE` before `return` statement
... 5 additional changes omitted for project

prefecthq/prefect (+0 -580 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --no-fix --output-format concise --preview

- examples/per_worker_task_concurrency.py:120:12: RET504 Unnecessary assignment to `result` before `return` statement
- examples/run_api_sourced_etl.py:105:12: RET504 Unnecessary assignment to `df` before `return` statement
- examples/run_api_sourced_etl.py:132:9: PERF401 Use a list comprehension to create a transformed list
- integration-tests/test_concurrency_leases.py:41:16: RET504 Unnecessary assignment to `limit` before `return` statement
- integration-tests/test_worker.py:25:13: PERF401 Use `list.extend` with an async comprehension to create a transformed list
- scripts/backfill_release_notes.py:199:13: PLR1714 Consider merging multiple comparisons. Use a `set` if the elements are hashable.
- scripts/backfill_release_notes.py:79:13: PERF401 Use a list comprehension to create a transformed list
- scripts/generate_settings_ref.py:110:13: PERF401 Use `list.extend` to create a transformed list
- scripts/prepare_integration_release_notes.py:121:9: TRY300 Consider moving this statement to an `else` block
- scripts/prepare_integration_release_notes.py:275:12: RET504 Unnecessary assignment to `body` before `return` statement
- scripts/prepare_integration_release_notes.py:311:12: RET504 Unnecessary assignment to `title` before `return` statement
- scripts/prepare_release_notes.py:207:13: PLR1714 Consider merging multiple comparisons. Use a `set` if the elements are hashable.
- scripts/prepare_release_notes.py:59:17: PERF401 Use a list comprehension to create a transformed list
- scripts/prepare_release_notes.py:87:16: RET504 Unnecessary assignment to `release_info` before `return` statement
- scripts/prepare_release_notes.py:87:9: TRY300 Consider moving this statement to an `else` block
- scripts/run-integration-flows.py:34:9: TRY300 Consider moving this statement to an `else` block
- src/integrations/prefect-aws/prefect_aws/_cli/utils.py:157:9: TRY300 Consider moving this statement to an `else` block
- src/integrations/prefect-aws/prefect_aws/_cli/utils.py:221:9: TRY300 Consider moving this statement to an `else` block
- src/integrations/prefect-aws/prefect_aws/_cli/utils.py:497:9: TRY300 Consider moving this statement to an `else` block
- src/integrations/prefect-aws/prefect_aws/assume_role_parameters.py:150:17: PERF403 Use a dictionary comprehension instead of a for-loop
- src/integrations/prefect-aws/prefect_aws/credentials.py:214:21: PERF403 Use `dict.update` instead of a for-loop
- src/integrations/prefect-aws/prefect_aws/credentials.py:57:12: RET504 Unnecessary assignment to `client` before `return` statement
- src/integrations/prefect-aws/prefect_aws/experimental/bundles/upload.py:72:9: TRY300 Consider moving this statement to an `else` block
- src/integrations/prefect-aws/prefect_aws/glue_job.py:174:13: TRY300 Consider moving this statement to an `else` block
- src/integrations/prefect-aws/prefect_aws/lambda_function.py:115:16: RET504 Unnecessary assignment to `lambda_client` before `return` statement
- src/integrations/prefect-aws/prefect_aws/plugins.py:35:16: RET504 Unnecessary assignment to `token` before `return` statement
... 375 additional changes omitted for rule RET504
- src/integrations/prefect-aws/prefect_aws/secrets_manager.py:153:9: TRY300 Consider moving this statement to an `else` block
... 87 additional changes omitted for rule TRY300
- src/integrations/prefect-aws/prefect_aws/workers/ecs_worker.py:1054:12: PLR1714 Consider merging multiple comparisons: `launch_type in {"FARGATE", "FARGATE_SPOT"}`.
- src/integrations/prefect-aws/prefect_aws/workers/ecs_worker.py:1210:12: PLR1714 Consider merging multiple comparisons: `launch_type in {"FARGATE", "FARGATE_SPOT"}`.
- src/integrations/prefect-azure/prefect_azure/blob_storage.py:755:21: PERF401 Use an async list comprehension to create a transformed list
- src/integrations/prefect-dask/prefect_dask/client.py:129:17: PERF401 Use a list comprehension to create a transformed list
- src/integrations/prefect-dask/tests/test_task_runners.py:279:17: PERF401 Use a list comprehension to create a transformed list
- src/integrations/prefect-dbt/prefect_dbt/cli/commands.py:1097:18: PLR1714 Consider merging multiple comparisons. Use a `set` if the elements are hashable.
- src/integrations/prefect-dbt/prefect_dbt/cli/commands.py:1101:18: PLR1714 Consider merging multiple comparisons: `r.status in (NodeStatus.Success, NodeStatus.Pass)`. Use a `set` if the elements are hashable.
- src/integrations/prefect-dbt/prefect_dbt/core/runner.py:1136:17: PERF403 Use a dictionary comprehension instead of a for-loop
- src/integrations/prefect-dbt/prefect_dbt/core/runner.py:660:21: PLR1714 Consider merging multiple comparisons. Use a `set` if the elements are hashable.
- src/integrations/prefect-dbt/prefect_dbt/core/runner.py:856:21: PLR1714 Consider merging multiple comparisons. Use a `set` if the elements are hashable.
- src/integrations/prefect-docker/prefect_docker/worker.py:323:45: PLR1714 Consider merging multiple comparisons: `host in {"127.0.0.1", "localhost"}`.
... 20 additional changes omitted for rule PLR1714
- src/integrations/prefect-docker/tests/test_worker.py:188:13: PERF401 Use `list.extend` to create a transformed list
... 62 additional changes omitted for rule PERF401
- src/prefect/utilities/engine.py:254:13: PERF403 Use `dict.update` instead of a for-loop
... 540 additional changes omitted for project

pypa/cibuildwheel (+0 -3 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --no-fix --output-format concise --preview

- bin/inspect_all_known_projects.py:33:9: TRY300 Consider moving this statement to an `else` block
- cibuildwheel/projectfiles.py:63:9: TRY300 Consider moving this statement to an `else` block
- cibuildwheel/venv.py:83:21: TRY300 Consider moving this statement to an `else` block

pypa/setuptools (+0 -3 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --no-fix --output-format concise --preview

- setuptools/command/bdist_egg.py:41:12: RET504 Unnecessary assignment to `filename` before `return` statement
- setuptools/depends.py:178:39: PLR1714 Consider merging multiple comparisons: `op in (STORE_NAME, STORE_GLOBAL)`. Use a `set` if the elements are hashable.
- setuptools/tests/config/test_apply_pyprojecttoml.py:409:16: RET504 Unnecessary assignment to `pyproject` before `return` statement

... Truncated remaining completed project reports due to GitHub comment length restrictions

Changes by rule (5 rules affected)

code total + violation - violation + fix - fix
RET504 457 0 457 0 0
TRY300 118 0 118 0 0
PERF401 107 0 107 0 0
PLR1714 36 0 36 0 0
PERF403 5 0 5 0 0

@amyreese
Copy link
Copy Markdown
Member

amyreese commented Mar 10, 2026

I'll personally be a tiny bit sad if SIM102 and SIM114 don't make it into the defaults. They seem like easy wins for both readability and simplicity.

@ntBre
Copy link
Copy Markdown
Contributor Author

ntBre commented Mar 10, 2026

I'll personally be a tiny bit sad if SIM102 and SIM114 don't make it into the defaults. They seem like easy wins for both readability and simplicity.

Yeah I'm a bit torn on these too. I think they're nice in simple cases like the ones in the docs, but I just ignored a Clippy lint for SIM114 today when I wanted the same code in each branch, and I also found some of the real examples on Discord clearly less readable. For example:

-if something in [value1, value2] and another > condition:
-    do_something()
-elif something_else == "a string" and condition:
+if something in [value1, value2] and another > condition or something_else == "a string" and condition:
     do_something()

Now I have to think about precedence, and it gets reformatted like this:

if (
    something in [value1, value2]
    and another > condition
    or something_else == "a string"
    and condition
):
    do_something()

I don't feel super strongly, but they have come up multiple times from different sources.

@amyreese
Copy link
Copy Markdown
Member

Wow, that suggested change should really come with wrapping parens to clarify OoO and where it previously came from, because that precedence is rough.

Copy link
Copy Markdown
Member

@MichaReiser MichaReiser left a comment

Choose a reason for hiding this comment

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

I feel similar to @amyreese. Should we leave the two SIM rules in the default set for now and improve their wording for better readability to see if that changes how the rules are perceived? We can still move them out later.

@ntBre
Copy link
Copy Markdown
Contributor Author

ntBre commented Mar 11, 2026

Sure, happy to leave the SIM rules in. I'll open a follow-up issue for improving the fixes.

@ntBre ntBre merged commit 0011f25 into main Mar 11, 2026
43 checks passed
@ntBre ntBre deleted the brent/default-rules-update branch March 11, 2026 17:36
ntBre added a commit to ntBre/default-rules that referenced this pull request Mar 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

preview Related to preview mode features rule-selection Related to enabling or disabling rules

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants