Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[pylint] Redefined outer names (PLW0621) #15903

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

InSyncWithFoo
Copy link
Contributor

@InSyncWithFoo InSyncWithFoo commented Feb 3, 2025

Summary

Part of #970 and #3040.

This partial implementation of W0621 reports parameters that overshadow a variable from an outer scope. Pytest (yield) fixtures are exempted from the rule.

The error message was taken from that of the upstream rule.

Test Plan

cargo nextest run and cargo insta test.

@InSyncWithFoo InSyncWithFoo marked this pull request as draft February 3, 2025 06:41
@InSyncWithFoo
Copy link
Contributor Author

That's weird. I'm pretty sure tests did pass when I wrote them two weeks ago.

Copy link
Contributor

github-actions bot commented Feb 11, 2025

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

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

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

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

+ disnake/abc.py:300:34: PLW0621 Redefining name `c` from outer scope (line 316)
+ disnake/ext/commands/core.py:1130:27: PLW0621 Redefining name `command` from outer scope (line 1534)
+ disnake/ext/commands/core.py:140:29: PLW0621 Redefining name `command` from outer scope (line 1534)
+ disnake/ext/commands/core.py:2533:5: PLW0621 Redefining name `cooldown` from outer scope (line 2493)
+ disnake/ext/commands/flag_converter.py:344:34: PLW0621 Redefining name `flag` from outer scope (line 95)
+ disnake/ext/commands/flag_converter.py:371:34: PLW0621 Redefining name `flag` from outer scope (line 95)
+ disnake/ext/commands/flag_converter.py:400:53: PLW0621 Redefining name `flag` from outer scope (line 95)
+ disnake/ext/commands/help.py:1009:38: PLW0621 Redefining name `no_category` from outer scope (line 1007)
+ disnake/ext/commands/help.py:1256:38: PLW0621 Redefining name `no_category` from outer scope (line 1254)
+ disnake/ext/commands/help.py:554:29: PLW0621 Redefining name `cmd` from outer scope (line 561)
... 79 additional changes omitted for project

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

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

+ aiven/client/cli.py:951:23: PLW0621 Redefining name `text` from outer scope (line 959)
+ tests/test_pretty.py:149:9: PLW0621 Redefining name `rows` from outer scope (line 128)
+ tests/test_pretty.py:159:30: PLW0621 Redefining name `actual` from outer scope (line 182)
+ tests/test_pretty.py:159:43: PLW0621 Redefining name `expected` from outer scope (line 183)
+ tests/test_pretty.py:77:9: PLW0621 Redefining name `rows` from outer scope (line 56)
+ tests/test_pretty.py:87:30: PLW0621 Redefining name `actual` from outer scope (line 110)
+ tests/test_pretty.py:87:43: PLW0621 Redefining name `expected` from outer scope (line 111)

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

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

+ .github/scripts/citation_updater.py:32:27: PLW0621 Redefining name `args` from outer scope (line 69)
+ docs/notebooks/diagnostics/charged_particle_radiography_particle_tracing.ipynb:cell 15:4:21: PLW0621 Redefining name `hax` from outer scope (line 151)
+ docs/notebooks/diagnostics/charged_particle_radiography_particle_tracing.ipynb:cell 15:4:26: PLW0621 Redefining name `vax` from outer scope (line 151)
+ docs/notebooks/diagnostics/charged_particle_radiography_particle_tracing.ipynb:cell 15:4:31: PLW0621 Redefining name `intensity` from outer scope (line 151)
+ docs/notebooks/diagnostics/charged_particle_radiography_particle_tracing_wire_mesh.ipynb:cell 16:1:20: PLW0621 Redefining name `sim` from outer scope (line 97)
+ docs/notebooks/dispersion/dispersion_function.ipynb:cell 9:1:18: PLW0621 Redefining name `X` from outer scope (line 29)
+ docs/notebooks/dispersion/dispersion_function.ipynb:cell 9:1:21: PLW0621 Redefining name `Y` from outer scope (line 29)
+ docs/notebooks/dispersion/stix_dispersion.ipynb:cell 27:7:29: PLW0621 Redefining name `mode` from outer scope (line 367)
+ docs/notebooks/dispersion/stix_dispersion.ipynb:cell 27:7:35: PLW0621 Redefining name `k_expected` from outer scope (line 296)
+ docs/notebooks/formulary/ExB_drift.ipynb:cell 6:1:32: PLW0621 Redefining name `v_d` from outer scope (line 64)
... 122 additional changes omitted for project

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

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

+ airflow/api_fastapi/app.py:129:23: PLW0621 Redefining name `app` from outer scope (line 44)
+ airflow/api_fastapi/app.py:49:20: PLW0621 Redefining name `app` from outer scope (line 44)
+ airflow/api_fastapi/execution_api/routes/xcoms.py:123:5: PLW0621 Redefining name `xcom_query` from outer scope (line 47)
+ airflow/api_fastapi/execution_api/routes/xcoms.py:96:5: PLW0621 Redefining name `xcom_query` from outer scope (line 47)
+ airflow/assets/manager.py:271:58: PLW0621 Redefining name `fileloc` from outer scope (line 283)
+ airflow/auth/managers/base_auth_manager.py:423:58: PLW0621 Redefining name `methods` from outer scope (line 415)
+ airflow/cli/commands/local_commands/webserver_command.py:459:40: PLW0621 Redefining name `args` from outer scope (line 324)
+ airflow/dag_processing/manager.py:542:30: PLW0621 Redefining name `abs_path` from outer scope (line 560)
+ airflow/decorators/base.py:140:27: PLW0621 Redefining name `dag` from outer scope (line 128)
+ airflow/decorators/base.py:679:27: PLW0621 Redefining name `python_callable` from outer scope (line 644)
+ airflow/example_dags/example_asset_decorator.py:32:36: PLW0621 Redefining name `asset1_producer` from outer scope (line 27)
+ airflow/example_dags/example_passing_params_via_test_command.py:34:43: PLW0621 Redefining name `task` from outer scope (line 28)
+ airflow/jobs/scheduler_job_runner.py:1455:27: PLW0621 Redefining name `dag` from outer scope (line 1507)
+ airflow/jobs/scheduler_job_runner.py:1455:37: PLW0621 Redefining name `dag_run` from outer scope (line 1502)
... 1915 additional changes omitted for project

apache/superset (+213 -11 violations, +0 -0 fixes)

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

+ RELEASING/verify_release.py:110:27: PLW0621 Redefining name `filename` from outer scope (line 127)
+ RELEASING/verify_release.py:29:21: PLW0621 Redefining name `filename` from outer scope (line 127)
+ RELEASING/verify_release.py:36:22: PLW0621 Redefining name `filename` from outer scope (line 127)
+ RELEASING/verify_release.py:45:19: PLW0621 Redefining name `filename` from outer scope (line 127)
+ RELEASING/verify_release.py:59:18: PLW0621 Redefining name `filename` from outer scope (line 127)
+ scripts/benchmark_migration.py:131:28: PLW0621 Redefining name `model` from outer scope (line 122)
... 197 additional changes omitted for rule PLW0621
- scripts/benchmark_migration.py:74:5: DOC201 `return` is not documented in docstring
+ scripts/benchmark_migration.py:74:5: DOC201 `return` is not documented in docstring
+ superset/migrations/shared/native_filters.py:287:5: D202 [*] No blank lines allowed after function docstring (found 1)
- superset/migrations/shared/native_filters.py:287:5: D202 [*] No blank lines allowed after function docstring (found 1)
... 214 additional changes omitted for project

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

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

+ samcli/commands/local/cli_common/invoke_context.py:313:43: PLW0621 Redefining name `function` from outer scope (line 326)
+ samcli/hook_packages/terraform/copy_terraform_built_artifacts.py:151:24: PLW0621 Redefining name `expression` from outer scope (line 348)
+ samcli/hook_packages/terraform/copy_terraform_built_artifacts.py:221:26: PLW0621 Redefining name `directory_path` from outer scope (line 347)
+ samcli/hook_packages/terraform/copy_terraform_built_artifacts.py:221:42: PLW0621 Redefining name `expression` from outer scope (line 348)
+ samcli/hook_packages/terraform/copy_terraform_built_artifacts.py:221:54: PLW0621 Redefining name `data_object` from outer scope (line 381)
+ samcli/lib/samlib/wrapper.py:93:30: PLW0621 Redefining name `self` from outer scope (line 85)
+ samcli/local/apigw/local_apigw_service.py:556:39: PLW0621 Redefining name `request` from outer scope (line 11)
+ tests/smoke/download_sar_templates.py:13:14: PLW0621 Redefining name `count` from outer scope (line 63)
+ tests/unit/hook_packages/terraform/hooks/prepare/test_types.py:17:26: PLW0621 Redefining name `self` from outer scope (line 15)
+ tests/unit/lib/build_module/test_app_builder.py:1497:26: PLW0621 Redefining name `self` from outer scope (line 1491)
... 9 additional changes omitted for project

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

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

+ examples/advanced/extensions/parallel_plot/parallel_plot.py:14:19: PLW0621 Redefining name `df` from outer scope (line 8)
+ examples/basic/annotations/colorbar_log.py:15:14: PLW0621 Redefining name `X` from outer scope (line 19)
+ examples/basic/annotations/colorbar_log.py:15:17: PLW0621 Redefining name `Y` from outer scope (line 19)
+ examples/basic/lines/lorenz.py:22:17: PLW0621 Redefining name `t` from outer scope (line 30)
+ examples/integration/embed/css_grid_simple.py:6:17: PLW0621 Redefining name `axes` from outer scope (line 39)
+ examples/integration/embed/css_grid_simple_no_extend.py:8:17: PLW0621 Redefining name `axes` from outer scope (line 50)
+ examples/integration/layout/multi_plot_layout.py:6:16: PLW0621 Redefining name `row` from outer scope (line 22)
+ examples/integration/layout/multi_plot_layout.py:6:21: PLW0621 Redefining name `col` from outer scope (line 21)
+ examples/integration/layout/multi_plot_layout.py:6:9: PLW0621 Redefining name `color` from outer scope (line 26)
+ examples/interaction/js_callbacks/js_on_event.py:15:19: PLW0621 Redefining name `div` from outer scope (line 54)
... 287 additional changes omitted for project

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

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

+ admin/bootstrap.py:135:30: PLW0621 Redefining name `args` from outer scope (line 327)
+ admin/bootstrap.py:164:14: PLW0621 Redefining name `args` from outer scope (line 327)
+ admin/bootstrap.py:222:22: PLW0621 Redefining name `args` from outer scope (line 327)
+ admin/bootstrap.py:233:5: PLW0621 Redefining name `args` from outer scope (line 327)
+ admin/bootstrap.py:95:14: PLW0621 Redefining name `args` from outer scope (line 327)
+ admin/securedrop_admin/__init__.py:661:26: PLW0621 Redefining name `self` from outer scope (line 653)
+ admin/tests/test_securedrop-admin.py:871:24: PLW0621 Redefining name `config` from outer scope (line 903)
+ admin/tests/test_securedrop-admin.py:880:24: PLW0621 Redefining name `config` from outer scope (line 903)
+ admin/tests/test_securedrop-admin.py:975:25: PLW0621 Redefining name `prompt` from outer scope (line 982)
+ admin/tests/test_securedrop-admin.py:975:33: PLW0621 Redefining name `default` from outer scope (line 982)
... 31 additional changes omitted for project

fronzbot/blinkpy (+4 -0 violations, +0 -0 fixes)

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

+ tests/test_util.py:105:29: PLW0621 Redefining name `self` from outer scope (line 98)
+ tests/test_util.py:110:29: PLW0621 Redefining name `self` from outer scope (line 98)
+ tests/test_util.py:66:28: PLW0621 Redefining name `self` from outer scope (line 60)
+ tests/test_util.py:87:22: PLW0621 Redefining name `self` from outer scope (line 77)

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

Changes by rule (7 rules affected)

code total + violation - violation + fix - fix
PLW0621 6440 6440 0 0 0
D415 6 3 3 0 0
DOC201 4 2 2 0 0
ANN201 4 2 2 0 0
D400 4 2 2 0 0
D103 4 2 2 0 0
D202 2 1 1 0 0

@InSyncWithFoo
Copy link
Contributor Author

Many of the violations look like this, where all as refer to the same object:

a = 0

def foo(a):
	...

def v():
	foo(a)

I'm in favor of reporting them, since such a parameter is unnecessary anyway, but the message/rule documentation could probably be improved to avoid potential confusion.

@dhruvmanila dhruvmanila added rule Implementing or modifying a lint rule preview Related to preview mode features labels Feb 12, 2025
@MichaReiser
Copy link
Member

Would you mind explaining what makes this rule a partial implementation of W0621 and why you decide to make it a ruff rule?

I don't think we should merge this as a ruff rule right now. It seems too opinionated. I'm okay to accept this as a pylint rule (if it is semantically close/the same)

@InSyncWithFoo
Copy link
Contributor Author

InSyncWithFoo commented Feb 12, 2025

(RUF059 is a tentative code and subjected to change.) There are two reasons for it to be this way:

  • I don't know exactly what W0621 does: the code is rather hard to read. The description only has one example, which shows a parameter shadowing an outer-scoped symbol, so I went with that.
  • I expected this to have a lot of violations. The first ecosystem check returned ~34k (class-scopes-related false positives), the second ~11k (collision with A002) and the third ~7k. A full implementation would have even more than that, making the PR harder to review from both sides.

@MichaReiser
Copy link
Member

Thanks for the extra context.

I don't think we should add a rule as a RUF rule that actually is a pylint rule that we later have to recode if it implements the full scope of the upstream rule. Especially if we don't understand what the differences are. I recommend to:

  • Implement it as a pylint rule. I'm fine if the rule doesn't implement all checks yet (but it will be a blocker for stabilization)
  • Create an issue that documents what's missing compared to the upstream rule.
  • Document the differences in the rule's description

@InSyncWithFoo InSyncWithFoo changed the title [ruff] Overshadowing parameters (RUF059) [pylint] Redefined outer names (PLW0621) Feb 12, 2025
@MichaReiser
Copy link
Member

Would you mind listing the differences to the upstream rule? Or do we still not know?

@InSyncWithFoo
Copy link
Contributor Author

@MichaReiser The upstream rule also reports variables and seems to have something to do with except handlers. Whatever I could make out of it I have already incorporated into the code.


Due to some reason, outer_16 is a false negative. I'm not sure why.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
preview Related to preview mode features rule Implementing or modifying a lint rule
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants