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

[refurb] implement repeated_global (FURB154) lint #11187

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

alex-700
Copy link
Contributor

Summary

Implement repeated_global (FURB154) lint.
See:

Test Plan

cargo test

Copy link
Contributor

github-actions bot commented Apr 28, 2024

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

ℹ️ ecosystem check detected linter changes. (+15 -0 violations, +0 -0 fixes in 3 projects; 41 projects unchanged)

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

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

+ airflow/plugins_manager.py:361:5: FURB154 [*] Use of repeated consecutive `global`
+ airflow/plugins_manager.py:422:5: FURB154 [*] Use of repeated consecutive `global`
+ airflow/plugins_manager.py:476:5: FURB154 [*] Use of repeated consecutive `global`
+ airflow/plugins_manager.py:503:5: FURB154 [*] Use of repeated consecutive `global`
+ airflow/providers/weaviate/hooks/weaviate.py:418:13: FURB154 [*] Use of repeated consecutive `nonlocal`
+ airflow/settings.py:192:5: FURB154 [*] Use of repeated consecutive `global`
+ airflow/settings.py:272:5: FURB154 [*] Use of repeated consecutive `global`
+ airflow/settings.py:399:5: FURB154 [*] Use of repeated consecutive `global`

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

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

+ tests/unit/bokeh/document/test_callbacks__document.py:168:13: FURB154 [*] Use of repeated consecutive `nonlocal`

zulip/zulip (+6 -0 violations, +0 -0 fixes)

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

+ zerver/data_import/slack.py:532:9: FURB154 [*] Use of repeated consecutive `nonlocal`
+ zerver/data_import/slack.py:604:9: FURB154 [*] Use of repeated consecutive `nonlocal`
+ zerver/lib/cache.py:63:5: FURB154 [*] Use of repeated consecutive `global`
+ zerver/lib/markdown/__init__.py:2718:5: FURB154 [*] Use of repeated consecutive `global`
+ zerver/lib/templates.py:106:5: FURB154 [*] Use of repeated consecutive `global`
+ zerver/tests/test_auth_backends.py:7621:13: FURB154 [*] Use of repeated consecutive `nonlocal`

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
FURB154 15 15 0 0 0

@charliermarsh
Copy link
Member

Since globals and nonlocals are rare, could we try instead running this rule on every global and nonlocal statement, and then, for each statement, mapping back to the containing Suite and looking for global statements that follow it repeatedly?

In other words... instead of iterating over every body / statement, can we instead run this for each global? You can look at traversal::next_sibling or traversal::suite (and their usages) for an example.

@alex-700
Copy link
Contributor Author

Since globals and nonlocals are rare, could we try instead running this rule on every global and nonlocal statement, and then, for each statement, mapping back to the containing Suite and looking for global statements that follow it repeatedly?

In other words... instead of iterating over every body / statement, can we instead run this for each global? You can look at traversal::next_sibling or traversal::suite (and their usages) for an example.

@charliermarsh done.
Just a note: now the algorithm is quadratic on len(suite) for each suite containing global or nonlocal. Instead of linear (and should be auto vectorized) for each suite.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants