Skip to content

Drop a few rules from the preview default set#23879

Open
ntBre wants to merge 6 commits intomainfrom
brent/default-rules-update
Open

Drop a few rules from the preview default set#23879
ntBre wants to merge 6 commits intomainfrom
brent/default-rules-update

Conversation

@ntBre
Copy link
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,
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.

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

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 -932 violations, +0 -0 fixes in 13 projects; 43 projects unchanged)

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

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

- aiven/client/argx.py:111:9: SIM102 Use a single `if` statement instead of nested `if` statements
- aiven/client/argx.py:112:13: SIM102 Use a single `if` statement instead of nested `if` statements
- aiven/client/cli.py:4168:9: SIM102 Use a single `if` statement instead of nested `if` statements
- aiven/client/cli.py:5215:13: SIM102 Use a single `if` statement instead of nested `if` statements
- aiven/client/cli.py:79:17: PERF401 Use a list comprehension to create a transformed list

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

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

- docker/api/build.py:128:9: SIM102 Use a single `if` statement instead of nested `if` statements
- docker/api/client.py:296:21: PERF403 Use `dict.update` instead of a for-loop
- docker/api/container.py:867:13: SIM114 [*] Combine `if` branches using logical `or` operator
- docker/api/container.py:884:13: SIM114 [*] Combine `if` branches using logical `or` operator
- docker/api/service.py:20:9: SIM102 Use a single `if` statement instead of nested `if` statements
- docker/api/service.py:26:9: SIM102 Use a single `if` statement instead of nested `if` statements
- docker/api/service.py:34:9: SIM102 Use a single `if` statement instead of nested `if` statements
- docker/api/service.py:38:5: SIM102 Use a single `if` statement instead of nested `if` statements
- docker/api/service.py:39:9: SIM102 Use a single `if` statement instead of nested `if` statements
... 12 additional changes omitted for rule SIM102
- docker/auth.py:263:13: TRY300 Consider moving this statement to an `else` block
... 21 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 -17 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/sample_similarity/resemblance_model.py:160:9: SIM102 Use a single `if` statement instead of nested `if` statements
- probatus/utils/arrayfuncs.py:106:9: SIM102 Use a single `if` statement instead of nested `if` statements
- 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
... 10 additional changes omitted for rule RET504
... 9 additional changes omitted for project

prefecthq/prefect (+0 -715 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:224:13: SIM102 Use a single `if` statement instead of nested `if` statements
- scripts/backfill_release_notes.py:236:13: SIM102 Use a single `if` statement instead of nested `if` statements
- scripts/backfill_release_notes.py:79:13: PERF401 Use a list comprehension to create a transformed list
- scripts/generate_example_pages.py:97:5: SIM102 Use a single `if` statement instead of nested `if` statements
- 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:232:13: SIM102 Use a single `if` statement instead of nested `if` statements
- scripts/prepare_release_notes.py:244:13: SIM102 Use a single `if` statement instead of nested `if` statements
- 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
... 378 additional changes omitted for rule RET504
- 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
... 90 additional changes omitted for rule TRY300
- 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/observers/ecs.py:492:9: SIM102 Use a single `if` statement instead of nested `if` statements
... 110 additional changes omitted for rule SIM102
- 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
... 65 additional changes omitted for rule PERF401
- 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.
... 23 additional changes omitted for rule PLR1714
- src/integrations/prefect-dbt/prefect_dbt/cloud/jobs.py:1011:13: SIM114 [*] Combine `if` branches using logical `or` operator
- src/integrations/prefect-dbt/prefect_dbt/cloud/jobs.py:580:9: SIM114 [*] Combine `if` branches using logical `or` operator
- src/integrations/prefect-dbt/prefect_dbt/core/runner.py:1136:17: PERF403 Use a dictionary comprehension instead of a for-loop
- src/integrations/prefect-docker/tests/conftest.py:116:13: SIM114 [*] Combine `if` branches using logical `or` operator
- src/prefect/_vendor/croniter/croniter.py:52:5: SIM114 [*] Combine `if` branches using logical `or` operator
- src/prefect/_vendor/croniter/croniter.py:54:5: SIM114 [*] Combine `if` branches using logical `or` operator
... 677 additional changes omitted for project

pypa/build (+0 -1 violations, +0 -0 fixes)

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

- tests/conftest.py:53:9: SIM102 Use a single `if` statement instead of nested `if` statements

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 -7 violations, +0 -0 fixes)

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

- setuptools/command/bdist_egg.py:137:13: SIM102 Use a single `if` statement instead of nested `if` statements
- setuptools/command/bdist_egg.py:316:17: SIM102 Use a single `if` statement instead of nested `if` statements
- setuptools/command/bdist_egg.py:41:12: RET504 Unnecessary assignment to `filename` before `return` statement
- setuptools/command/build_ext.py:82:9: SIM114 [*] Combine `if` branches using logical `or` operator
- setuptools/command/install.py:77:9: SIM102 Use a single `if` statement instead of nested `if` statements
- 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 (7 rules affected)

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

@amyreese
Copy link
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
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
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.

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.

2 participants