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] Mark autofix for RUF052 as always unsafe #14824

Merged
merged 3 commits into from
Dec 9, 2024
Merged

Conversation

AlexWaygood
Copy link
Member

Summary

#14819 improved the autofix offered by this rule for a bunch of standard-library classes that must be instantiated according to the pattern T = TypeVar("T"), where the string literal passed to the constructor must match the name of the variable the call is being assigned to. However, there may be examples of this pattern in third-party libraries that we don't know about, so we can't assume that this fix is now safe.

TODO: needs a comment in crates/ruff_linter/src/rules/ruff/rules/used_dummy_variable.rs about why it's marked as unsafe

Test Plan

cargo test -p ruff_linter

@AlexWaygood AlexWaygood added fixes Related to suggested fixes for violations preview Related to preview mode features labels Dec 6, 2024
Copy link
Collaborator

@dylwil3 dylwil3 left a comment

Choose a reason for hiding this comment

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

Seems like the safest thing to do!

Copy link
Contributor

github-actions bot commented Dec 6, 2024

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

ℹ️ ecosystem check detected linter changes. (+66 -0 violations, +0 -1002 fixes in 20 projects; 35 projects unchanged)

DisnakeDev/disnake (+0 -0 violations, +0 -32 fixes)

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

+ disnake/errors.py:80:17: RUF052 Local dummy variable `_errors` is accessed
- disnake/errors.py:80:17: RUF052 [*] Local dummy variable `_errors` is accessed
+ disnake/ext/commands/converter.py:1294:9: RUF052 Local dummy variable `_NoneType` is accessed
- disnake/ext/commands/converter.py:1294:9: RUF052 [*] Local dummy variable `_NoneType` is accessed
+ disnake/ext/commands/view.py:118:13: RUF052 Local dummy variable `_escaped_quotes` is accessed
- disnake/ext/commands/view.py:118:13: RUF052 [*] Local dummy variable `_escaped_quotes` is accessed
+ disnake/guild.py:5159:9: RUF052 Local dummy variable `_id` is accessed
- disnake/guild.py:5159:9: RUF052 [*] Local dummy variable `_id` is accessed
+ disnake/guild.py:5309:9: RUF052 Local dummy variable `_id` is accessed
- disnake/guild.py:5309:9: RUF052 [*] Local dummy variable `_id` is accessed
... 22 additional changes omitted for project

RasaHQ/rasa (+0 -0 violations, +0 -112 fixes)

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

+ rasa/api.py:42:5: RUF052 Local dummy variable `_endpoints` is accessed
- rasa/api.py:42:5: RUF052 [*] Local dummy variable `_endpoints` is accessed
+ rasa/core/actions/action.py:1218:9: RUF052 Local dummy variable `_tracker` is accessed
- rasa/core/actions/action.py:1218:9: RUF052 [*] Local dummy variable `_tracker` is accessed
+ rasa/core/actions/action.py:603:9: RUF052 Local dummy variable `_events` is accessed
- rasa/core/actions/action.py:603:9: RUF052 [*] Local dummy variable `_events` is accessed
+ rasa/core/actions/forms.py:274:9: RUF052 Local dummy variable `_tracker` is accessed
- rasa/core/actions/forms.py:274:9: RUF052 [*] Local dummy variable `_tracker` is accessed
+ rasa/core/actions/forms.py:276:9: RUF052 Local dummy variable `_action` is accessed
- rasa/core/actions/forms.py:276:9: RUF052 [*] Local dummy variable `_action` is accessed
... 102 additional changes omitted for project

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

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

+ airflow/api_connexion/endpoints/pool_endpoint.py:135:9: RUF052 Local dummy variable `_patch_body` is accessed
- airflow/api_connexion/endpoints/pool_endpoint.py:135:9: RUF052 [*] Local dummy variable `_patch_body` is accessed
+ airflow/assets/manager.py:280:5: RUF052 Local dummy variable `_asset_manager_class` is accessed
- airflow/assets/manager.py:280:5: RUF052 [*] Local dummy variable `_asset_manager_class` is accessed
+ airflow/assets/manager.py:285:5: RUF052 Local dummy variable `_asset_manager_kwargs` is accessed
- airflow/assets/manager.py:285:5: RUF052 [*] Local dummy variable `_asset_manager_kwargs` is accessed
+ airflow/cli/commands/local_commands/info_command.py:263:9: RUF052 Local dummy variable `_locale` is accessed
- airflow/cli/commands/local_commands/info_command.py:263:9: RUF052 [*] Local dummy variable `_locale` is accessed
+ airflow/cli/commands/remote_commands/connection_command.py:152:5: RUF052 Local dummy variable `_connection_types` is accessed
- airflow/cli/commands/remote_commands/connection_command.py:152:5: RUF052 [*] Local dummy variable `_connection_types` is accessed
+ airflow/cli/commands/remote_commands/task_command.py:456:9: RUF052 Local dummy variable `_dag` is accessed
- airflow/cli/commands/remote_commands/task_command.py:456:9: RUF052 [*] Local dummy variable `_dag` is accessed
+ airflow/configuration.py:1300:13: RUF052 Local dummy variable `_section` is accessed
- airflow/configuration.py:1300:13: RUF052 [*] Local dummy variable `_section` is accessed
+ airflow/dag_processing/processor.py:237:26: RUF052 Local dummy variable `_child_channel` is accessed
... 313 additional changes omitted for project

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

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

+ superset/connectors/sqla/models.py:461:17: RUF052 Local dummy variable `_columns` is accessed
- superset/connectors/sqla/models.py:461:17: RUF052 [*] Local dummy variable `_columns` is accessed
+ superset/db_engine_specs/presto.py:149:13: RUF052 Local dummy variable `_column` is accessed
- superset/db_engine_specs/presto.py:149:13: RUF052 [*] Local dummy variable `_column` is accessed
+ superset/migrations/versions/2018-11-12_13-31_4ce8df208545_migrate_time_range_for_default_filters.py:71:29: RUF052 Local dummy variable `__from` is accessed
- superset/migrations/versions/2018-11-12_13-31_4ce8df208545_migrate_time_range_for_default_filters.py:71:29: RUF052 [*] Local dummy variable `__from` is accessed
+ superset/migrations/versions/2018-11-12_13-31_4ce8df208545_migrate_time_range_for_default_filters.py:72:29: RUF052 Local dummy variable `__to` is accessed
- superset/migrations/versions/2018-11-12_13-31_4ce8df208545_migrate_time_range_for_default_filters.py:72:29: RUF052 [*] Local dummy variable `__to` is accessed
+ superset/models/helpers.py:1648:21: RUF052 Local dummy variable `_sql` is accessed
- superset/models/helpers.py:1648:21: RUF052 [*] Local dummy variable `_sql` is accessed
... 68 additional changes omitted for project

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

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

+ src/bokeh/application/handlers/code_runner.py:219:9: RUF052 Local dummy variable `_cwd` is accessed
- src/bokeh/application/handlers/code_runner.py:219:9: RUF052 [*] Local dummy variable `_cwd` is accessed
+ src/bokeh/application/handlers/code_runner.py:220:9: RUF052 Local dummy variable `_sys_path` is accessed
- src/bokeh/application/handlers/code_runner.py:220:9: RUF052 [*] Local dummy variable `_sys_path` is accessed
+ src/bokeh/application/handlers/code_runner.py:221:9: RUF052 Local dummy variable `_sys_argv` is accessed
- src/bokeh/application/handlers/code_runner.py:221:9: RUF052 [*] Local dummy variable `_sys_argv` is accessed
+ src/bokeh/command/subcommands/static.py:79:9: RUF052 Local dummy variable `_allowed_keys` is accessed
- src/bokeh/command/subcommands/static.py:79:9: RUF052 [*] Local dummy variable `_allowed_keys` is accessed
+ src/bokeh/core/property/bases.py:450:9: RUF052 Local dummy variable `_type_params` is accessed
- src/bokeh/core/property/bases.py:450:9: RUF052 [*] Local dummy variable `_type_params` is accessed
... 28 additional changes omitted for project

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

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

+ .github/workflows/algolia/upload-algolia-api.py:174:9: RUF052 Local dummy variable `_creator` is accessed
- .github/workflows/algolia/upload-algolia-api.py:174:9: RUF052 [*] Local dummy variable `_creator` is accessed
+ ibis/backends/impala/ddl.py:16:9: RUF052 Local dummy variable `_format_aliases` is accessed
- ibis/backends/impala/ddl.py:16:9: RUF052 [*] Local dummy variable `_format_aliases` is accessed
+ ibis/backends/mssql/__init__.py:720:17: RUF052 Local dummy variable `_table` is accessed
- ibis/backends/mssql/__init__.py:720:17: RUF052 [*] Local dummy variable `_table` is accessed
+ ibis/backends/polars/compiler.py:621:5: RUF052 Local dummy variable `_lpad` is accessed
- ibis/backends/polars/compiler.py:621:5: RUF052 [*] Local dummy variable `_lpad` is accessed
+ ibis/backends/polars/compiler.py:628:5: RUF052 Local dummy variable `_rpad` is accessed
- ibis/backends/polars/compiler.py:628:5: RUF052 [*] Local dummy variable `_rpad` is accessed
... 10 additional changes omitted for project

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

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

+ src/latch_cli/services/get_params.py:140:17: RUF052 Local dummy variable `_enum_literal` is accessed
- src/latch_cli/services/get_params.py:140:17: RUF052 [*] Local dummy variable `_enum_literal` is accessed
+ src/latch_cli/services/get_params.py:146:21: RUF052 Local dummy variable `_enum_literal` is accessed
- src/latch_cli/services/get_params.py:146:21: RUF052 [*] Local dummy variable `_enum_literal` is accessed
+ src/latch_cli/services/launch.py:143:5: RUF052 Local dummy variable `_interface_request` is accessed
- src/latch_cli/services/launch.py:143:5: RUF052 [*] Local dummy variable `_interface_request` is accessed
+ src/latch_cli/services/launch.py:208:5: RUF052 Local dummy variable `_interface_request` is accessed
- src/latch_cli/services/launch.py:208:5: RUF052 [*] Local dummy variable `_interface_request` is accessed
+ src/latch_cli/services/register/utils.py:127:5: RUF052 Local dummy variable `_env` is accessed
- src/latch_cli/services/register/utils.py:127:5: RUF052 [*] Local dummy variable `_env` is accessed
... 2 additional changes omitted for project

lnbits/lnbits (+0 -0 violations, +0 -8 fixes)

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

+ tests/wallets/fixtures/models.py:35:9: RUF052 Local dummy variable `_mock` is accessed
- tests/wallets/fixtures/models.py:35:9: RUF052 [*] Local dummy variable `_mock` is accessed
+ tests/wallets/helpers.py:117:13: RUF052 Local dummy variable `_assert` is accessed
- tests/wallets/helpers.py:117:13: RUF052 [*] Local dummy variable `_assert` is accessed
+ tests/wallets/test_rpc_wallets.py:159:17: RUF052 Local dummy variable `_mock_class` is accessed
- tests/wallets/test_rpc_wallets.py:159:17: RUF052 [*] Local dummy variable `_mock_class` is accessed
+ tests/wallets/test_rpc_wallets.py:66:9: RUF052 Local dummy variable `_mock_class` is accessed
- tests/wallets/test_rpc_wallets.py:66:9: RUF052 [*] Local dummy variable `_mock_class` is accessed

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

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
RUF052 1068 66 0 0 1002

@AlexWaygood AlexWaygood marked this pull request as ready for review December 9, 2024 13:05
@AlexWaygood
Copy link
Member Author

Thanks @dylwil3! I just pushed some docs to try to explain why it's marked as unsafe; could you take a quick second look?

@AlexWaygood AlexWaygood requested a review from dylwil3 December 9, 2024 13:07
Copy link
Collaborator

@dylwil3 dylwil3 left a comment

Choose a reason for hiding this comment

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

Looks good! Suggested possible rewording, but it's also fine as is

Comment on lines 58 to 59
/// As well as renaming the variable itself, the fix iterates through all references to the
/// variable and adapts them to become references to the renamed variable. However, some renamings
Copy link
Collaborator

Choose a reason for hiding this comment

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

How about:

- /// As well as renaming the variable itself, the fix iterates through all references to the
- /// variable and adapts them to become references to the renamed variable. However, some renamings
+ /// Ruff will attempt to rename the variable and all references to it. However, some renamings

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm... I like the improved concision... but I'm not sure about talking about "renaming references". I feel like, strictly speaking, the binding is renamed, but the references do not have a "name" as such (so they cannot be renamed), they only point to (refer) to a name.

I'll push something that's more concise than what I've got currently, though ;)

Thanks!

@AlexWaygood AlexWaygood enabled auto-merge (squash) December 9, 2024 23:07
@AlexWaygood AlexWaygood merged commit e3f34b8 into main Dec 9, 2024
20 checks passed
@AlexWaygood AlexWaygood deleted the alex/unsafe-ruf052 branch December 9, 2024 23:11
dcreager added a commit that referenced this pull request Dec 10, 2024
* main:
  [`airflow`] Add fix to remove deprecated keyword arguments (`AIR302`) (#14887)
  Improve mdtests style (#14884)
  Reference `suppress-dummy-regex-options` in documentation of rules supporting it (#14888)
  [`flake8-bugbear`] `itertools.batched()` without explicit `strict` (`B911`) (#14408)
  [`ruff`] Mark autofix for `RUF052` as always unsafe (#14824)
  [red-knot] Improve type inference for except handlers (#14838)
  More typos found by codespell (#14880)
  [red-knot] move standalone expression_ty to TypeInferenceBuilder::file_expression_ty (#14879)
  [`ruff`] Do not simplify `round()` calls (`RUF046`) (#14832)
  Stop referring to early ruff versions (#14862)
  Fix a typo in `class.rs` (#14877)
  [`flake8-pyi`] Also remove `self` and `cls`'s annotation (`PYI034`) (#14801)
  [`pyupgrade`] Remove unreachable code in `UP015` implementation (#14871)
  [`flake8-bugbear`] Skip `B028` if `warnings.warn` is called with `*args` or `**kwargs` (#14870)
Elno5

This comment was marked as off-topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixes Related to suggested fixes for violations preview Related to preview mode features
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants