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

[Ruff 0.6] Stabilise PLR6104 #12858

Merged
merged 1 commit into from
Aug 13, 2024
Merged

[Ruff 0.6] Stabilise PLR6104 #12858

merged 1 commit into from
Aug 13, 2024

Conversation

AlexWaygood
Copy link
Member

Split out from #12857 so that it can be considered in isolation.

Summary

This PR stabilises the non-augmented-assignment pylint rule (PLR6104). I think this rule makes sense and is reasonably uncontroversial. It's been in preview for >3 months and there haven't been any significant issues opened about it in several months.

However, it's a stylistic rule that's somewhat pedantic, and it has a lot of ecosystem hits.

Test Plan

cargo test

Copy link
Contributor

ruff-ecosystem results

Linter (stable)

ℹ️ ecosystem check detected linter changes. (+358 -0 violations, +0 -0 fixes in 11 projects; 43 projects unchanged)

PlasmaPy/PlasmaPy (+33 -0 violations, +0 -0 fixes)

+ src/plasmapy/analysis/time_series/running_moments.py:61:5: PLR6104 Use `-=` to perform an augmented assignment directly
+ src/plasmapy/diagnostics/charged_particle_radiography/synthetic_radiography.py:440:13: PLR6104 Use `/=` to perform an augmented assignment directly
+ src/plasmapy/diagnostics/charged_particle_radiography/synthetic_radiography.py:446:13: PLR6104 Use `/=` to perform an augmented assignment directly
+ src/plasmapy/diagnostics/charged_particle_radiography/synthetic_radiography.py:777:9: PLR6104 Use `+=` to perform an augmented assignment directly
+ src/plasmapy/diagnostics/langmuir.py:1398:5: PLR6104 Use `/=` to perform an augmented assignment directly
+ src/plasmapy/diagnostics/langmuir.py:809:9: PLR6104 Use `-=` to perform an augmented assignment directly
+ src/plasmapy/diagnostics/thomson.py:199:5: PLR6104 Use `/=` to perform an augmented assignment directly
+ src/plasmapy/diagnostics/thomson.py:553:5: PLR6104 Use `/=` to perform an augmented assignment directly
+ src/plasmapy/diagnostics/thomson.py:554:5: PLR6104 Use `/=` to perform an augmented assignment directly
+ src/plasmapy/diagnostics/thomson.py:933:5: PLR6104 Use `/=` to perform an augmented assignment directly
... 23 additional changes omitted for project

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

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

+ airflow/io/path.py:292:13: PLR6104 Use `/=` to perform an augmented assignment directly
+ airflow/io/path.py:294:13: PLR6104 Use `/=` to perform an augmented assignment directly
+ airflow/jobs/scheduler_job_runner.py:869:37: PLR6104 Use `+=` to perform an augmented assignment directly
+ airflow/kubernetes/pre_7_4_0_compatibility/kube_client.py:89:5: PLR6104 Use `+=` to perform an augmented assignment directly
+ airflow/kubernetes/pre_7_4_0_compatibility/kube_client.py:90:5: PLR6104 Use `+=` to perform an augmented assignment directly
+ airflow/providers/amazon/aws/hooks/eks.py:546:13: PLR6104 Use `+=` to perform an augmented assignment directly
+ airflow/providers/amazon/aws/hooks/eks.py:549:13: PLR6104 Use `+=` to perform an augmented assignment directly
+ airflow/providers/cncf/kubernetes/kube_client.py:90:5: PLR6104 Use `+=` to perform an augmented assignment directly
+ airflow/providers/cncf/kubernetes/kube_client.py:91:5: PLR6104 Use `+=` to perform an augmented assignment directly
+ airflow/providers/teradata/transfers/s3_to_teradata.py:106:21: PLR6104 Use `+=` to perform an augmented assignment directly
... 34 additional changes omitted for project

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

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

+ scripts/build_docker.py:284:9: PLR6104 Use `+=` to perform an augmented assignment directly
+ superset/advanced_data_type/plugins/internet_address.py:93:17: PLR6104 Use `|=` to perform an augmented assignment directly
+ superset/common/query_context_processor.py:618:17: PLR6104 Use `+=` to perform an augmented assignment directly
+ superset/db_engine_specs/base.py:1156:13: PLR6104 Use `+=` to perform an augmented assignment directly
+ superset/migrations/shared/security_converge.py:259:13: PLR6104 Use `+=` to perform an augmented assignment directly
+ superset/migrations/shared/security_converge.py:272:17: PLR6104 Use `+=` to perform an augmented assignment directly
+ superset/migrations/versions/2018-02-13_08-07_e866bd2d4976_smaller_grid.py:57:17: PLR6104 Use `*=` to perform an augmented assignment directly
+ superset/migrations/versions/2018-02-13_08-07_e866bd2d4976_smaller_grid.py:58:17: PLR6104 Use `*=` to perform an augmented assignment directly
+ superset/migrations/versions/2018-02-13_08-07_e866bd2d4976_smaller_grid.py:60:17: PLR6104 Use `*=` to perform an augmented assignment directly
+ superset/migrations/versions/2018-02-13_08-07_e866bd2d4976_smaller_grid.py:79:17: PLR6104 Use `/=` to perform an augmented assignment directly
... 14 additional changes omitted for project

aws/aws-sam-cli (+128 -0 violations, +0 -0 fixes)

+ samcli/commands/_utils/table_print.py:46:9: PLR6104 Use `-=` to perform an augmented assignment directly
+ samcli/commands/init/interactive_event_bridge_flow.py:174:9: PLR6104 Use `+=` to perform an augmented assignment directly
+ samcli/lib/build/bundler.py:178:13: PLR6104 Use `+=` to perform an augmented assignment directly
+ samcli/lib/deploy/deployer.py:468:17: PLR6104 Use `+=` to perform an augmented assignment directly
+ samcli/lib/deploy/deployer.py:820:13: PLR6104 Use `+=` to perform an augmented assignment directly
+ samcli/lib/schemas/cli_paginator.py:27:9: PLR6104 Use `+=` to perform an augmented assignment directly
+ samcli/lib/schemas/cli_paginator.py:34:9: PLR6104 Use `+=` to perform an augmented assignment directly
+ samcli/lib/schemas/cli_paginator.py:38:9: PLR6104 Use `+=` to perform an augmented assignment directly
+ samcli/lib/schemas/cli_paginator.py:42:9: PLR6104 Use `+=` to perform an augmented assignment directly
+ samcli/lib/schemas/cli_paginator.py:59:9: PLR6104 Use `-=` to perform an augmented assignment directly
+ samcli/lib/schemas/schemas_aws_config.py:52:9: PLR6104 Use `+=` to perform an augmented assignment directly
+ samcli/lib/schemas/schemas_directory_hierarchy_builder.py:14:9: PLR6104 Use `+=` to perform an augmented assignment directly
+ samcli/lib/schemas/schemas_directory_hierarchy_builder.py:21:13: PLR6104 Use `+=` to perform an augmented assignment directly
+ samcli/lib/schemas/schemas_directory_hierarchy_builder.py:22:13: PLR6104 Use `+=` to perform an augmented assignment directly
+ samcli/lib/utils/retry.py:34:21: PLR6104 Use `+=` to perform an augmented assignment directly
+ samcli/lib/utils/retry.py:35:21: PLR6104 Use `-=` to perform an augmented assignment directly
+ samcli/local/docker/lambda_container.py:131:17: PLR6104 Use `+=` to perform an augmented assignment directly
... 111 additional changes omitted for project

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

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

+ src/bokeh/resources.py:379:13: PLR6104 Use `+=` to perform an augmented assignment directly
+ src/bokeh/server/util.py:96:9: PLR6104 Use `+=` to perform an augmented assignment directly
+ src/bokeh/util/token.py:308:9: PLR6104 Use `+=` to perform an augmented assignment directly

freedomofpress/securedrop (+1 -0 violations, +0 -0 fixes)

+ securedrop/tests/test_journalist.py:1864:9: PLR6104 Use `+=` to perform an augmented assignment directly

ibis-project/ibis (+6 -0 violations, +0 -0 fixes)

+ ibis/backends/bigquery/tests/unit/udf/test_usage.py:25:5: PLR6104 Use `+=` to perform an augmented assignment directly
+ ibis/backends/pandas/executor.py:718:17: PLR6104 Use `&=` to perform an augmented assignment directly
+ ibis/common/tests/test_numeric.py:63:13: PLR6104 Use `+=` to perform an augmented assignment directly
+ ibis/common/tests/test_numeric.py:68:13: PLR6104 Use `+=` to perform an augmented assignment directly
+ ibis/common/tests/test_numeric.py:75:13: PLR6104 Use `+=` to perform an augmented assignment directly
+ ibis/expr/tests/test_api.py:171:9: PLR6104 Use `+=` to perform an augmented assignment directly

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

+ examples/example_bulkinsert_json.py:142:9: PLR6104 Use `+=` to perform an augmented assignment directly
+ examples/example_bulkinsert_json.py:224:13: PLR6104 Use `+=` to perform an augmented assignment directly
+ examples/example_bulkinsert_json.py:247:13: PLR6104 Use `+=` to perform an augmented assignment directly
+ examples/example_bulkinsert_json.py:249:13: PLR6104 Use `+=` to perform an augmented assignment directly
+ examples/example_bulkinsert_json.py:251:13: PLR6104 Use `+=` to perform an augmented assignment directly
+ examples/example_bulkinsert_json.py:253:13: PLR6104 Use `+=` to perform an augmented assignment directly
+ examples/example_bulkinsert_json.py:255:13: PLR6104 Use `+=` to perform an augmented assignment directly
+ examples/example_bulkinsert_numpy.py:132:5: PLR6104 Use `+=` to perform an augmented assignment directly
+ examples/example_bulkinsert_numpy.py:226:13: PLR6104 Use `+=` to perform an augmented assignment directly
+ examples/example_bulkinsert_numpy.py:249:13: PLR6104 Use `+=` to perform an augmented assignment directly
... 20 additional changes omitted for project

pandas-dev/pandas (+85 -0 violations, +0 -0 fixes)

+ asv_bench/benchmarks/algos/isin.py:136:13: PLR6104 Use `+=` to perform an augmented assignment directly
+ asv_bench/benchmarks/arithmetic.py:141:13: PLR6104 Use `//=` to perform an augmented assignment directly
+ pandas/core/algorithms.py:916:9: PLR6104 Use `/=` to perform an augmented assignment directly
+ pandas/core/apply.py:1868:9: PLR6104 Use `+=` to perform an augmented assignment directly
+ pandas/core/arrays/arrow/array.py:2545:9: PLR6104 Use `+=` to perform an augmented assignment directly
+ pandas/core/arrays/boolean.py:232:17: PLR6104 Use `|=` to perform an augmented assignment directly
+ pandas/core/arrays/boolean.py:239:17: PLR6104 Use `|=` to perform an augmented assignment directly
+ pandas/core/arrays/masked.py:689:17: PLR6104 Use `|=` to perform an augmented assignment directly
+ pandas/core/arrays/masked.py:691:17: PLR6104 Use `|=` to perform an augmented assignment directly
+ pandas/core/arrays/masked.py:942:13: PLR6104 Use `^=` to perform an augmented assignment directly
+ pandas/core/arrays/period.py:1226:9: PLR6104 Use `*=` to perform an augmented assignment directly
... 74 additional changes omitted for project

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

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
PLR6104 358 358 0 0 0

Linter (preview)

✅ ecosystem check detected no linter changes.

@MichaReiser MichaReiser added the rule Implementing or modifying a lint rule label Aug 13, 2024
@MichaReiser
Copy link
Member

Yeah, i"m not entirely sure about this one either.

I do think it improves readability in some cases because it makes the precedence more clear. But the fact that the rule has no fix (according to the ecosystem results) makes the adoption fairly painful.

To me it's not entirely clear if I would consider this an idiomatic rule or a stylistic rule. If it's the latter, then our rule acceptance guidelines would say that we should not accept the rule. If it's idiomatic, then I would probably go ahead

@AlexWaygood
Copy link
Member Author

But the fact that the rule has no fix (according to the ecosystem results) makes the adoption fairly painful.

it seems like it does have an autofix, but that the autofix must be marked as unsafe in many situations :/

@AlexWaygood
Copy link
Member Author

Having discussed this offline, we'll merge this since:

  • It's included as a builtin rule in the original pylint tool
  • It's not enabled by default
  • It's easy to switch off the rule if you don't like it
  • Our pylint rules in general are somewhat more pedantic and opinionated than our other rules

@AlexWaygood AlexWaygood merged commit cea8d57 into ruff-0.6 Aug 13, 2024
20 checks passed
@AlexWaygood AlexWaygood deleted the stabilise-PLR6104 branch August 13, 2024 15:21
@MichaReiser MichaReiser mentioned this pull request Aug 13, 2024
@kdebrab
Copy link

kdebrab commented Aug 13, 2024

@AlexWaygood I'm a bit concerned about this rule, because there are quite some cases where the application would unintentionally introduce nasty and hard-to-find bugs, in particular when it is applied on input arguments of a function. I'm afraid one could sometimes not be aware that applying the fix causes bugs for these cases. It is especially prevalent for data science libraries when working with numpy arrays or pandas Series / DataFrames, but it could also happen in case the argument is a dictionary or list. In my view, these are false positives which could and should be avoided by not applying the rule on variables that are function arguments.

Skimming through the examples above from the ecosystem, I found 10 such cases where applying the fix would lead to (not always evident) bugs:

PlasmaPy/PlasmaPy

pandas-dev/pandas

Would it be possible to somehow avoid raising PLR6104 for variables that are function arguments?

@zanieb
Copy link
Member

zanieb commented Aug 13, 2024

By chance, I think the first one I clicked on (pandas/core/arrays/boolean.py#L239) is not a bug? I opened a couple others and you look correct though. I think that's a fair point, it does seem especially dangerous to apply this rule to variables bound to function inputs. I'm not sure if we have logic based on that already, it seems feasible?

What's the deal with this rule in Pylint? Does it have the same problems? i.e. does it report violations for the examples you selected?

@AlexWaygood
Copy link
Member Author

Thanks for speaking up @kdebrab, really appreciate it. I'll revert this PR tomorrow morning before we cut the release, so we can take our time to consider this more fully.

@AlexWaygood
Copy link
Member Author

Reverted in #12884

@AlexWaygood
Copy link
Member Author

I've opened #12890 to discuss if we can reduce the number of unsafe recommendations from this rule.

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.

4 participants