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

Consider with statements for too many branches lint #11321

Merged

Conversation

blueraft
Copy link
Contributor

@blueraft blueraft commented May 7, 2024

Resolves #11313

Summary

PLR0912(too-many-branches) did not count branches inside with: blocks. With this fix, the branches inside with statements are also counted.

Test Plan

Added a new test case.

Copy link
Contributor

github-actions bot commented May 7, 2024

ruff-ecosystem results

Linter (stable)

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

apache/airflow (+29 -6 violations, +0 -0 fixes)

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

- airflow/cli/commands/connection_command.py:209:5: PLR0912 Too many branches (17 > 12)
+ airflow/cli/commands/connection_command.py:209:5: PLR0912 Too many branches (19 > 12)
- airflow/cli/commands/task_command.py:404:5: PLR0912 Too many branches (15 > 12)
+ airflow/cli/commands/task_command.py:404:5: PLR0912 Too many branches (16 > 12)
- airflow/cli/commands/task_command.py:631:5: PLR0912 Too many branches (16 > 12)
+ airflow/cli/commands/task_command.py:631:5: PLR0912 Too many branches (18 > 12)
+ airflow/models/dagrun.py:755:9: PLR0912 Too many branches (15 > 12)
+ airflow/models/taskinstance.py:2489:9: PLR0912 Too many branches (24 > 12)
- airflow/models/taskinstance.py:400:5: PLR0912 Too many branches (14 > 12)
+ airflow/models/taskinstance.py:400:5: PLR0912 Too many branches (22 > 12)
+ airflow/providers/apache/hive/transfers/s3_to_hive.py:141:9: PLR0912 Too many branches (17 > 12)
+ airflow/providers/apache/livy/hooks/livy.py:496:15: PLR0912 Too many branches (16 > 12)
+ airflow/providers/cncf/kubernetes/executors/kubernetes_executor.py:213:9: PLR0912 Too many branches (16 > 12)
+ airflow/providers/cncf/kubernetes/executors/kubernetes_executor.py:379:9: PLR0912 Too many branches (17 > 12)
+ airflow/providers/common/sql/hooks/sql.py:356:9: PLR0912 Too many branches (14 > 12)
+ airflow/providers/databricks/hooks/databricks_sql.py:199:9: PLR0912 Too many branches (16 > 12)
+ airflow/providers/databricks/operators/databricks_sql.py:126:9: PLR0912 Too many branches (13 > 12)
+ airflow/providers/elasticsearch/log/es_task_handler.py:216:9: PLR0912 Too many branches (14 > 12)
+ airflow/providers/exasol/hooks/exasol.py:187:9: PLR0912 Too many branches (14 > 12)
+ airflow/providers/google/cloud/operators/gcs.py:792:9: PLR0912 Too many branches (20 > 12)
+ airflow/providers/http/hooks/http.py:318:15: PLR0912 Too many branches (24 > 12)
+ airflow/providers/openlineage/utils/utils.py:305:9: PLR0912 Too many branches (13 > 12)
+ airflow/providers/snowflake/hooks/snowflake.py:340:9: PLR0912 Too many branches (14 > 12)
+ airflow/utils/db.py:1554:5: PLR0912 Too many branches (16 > 12)
+ airflow/www/views.py:3424:9: PLR0912 Too many branches (13 > 12)
+ airflow/www/views.py:739:9: PLR0912 Too many branches (36 > 12)
+ dev/breeze/src/airflow_breeze/commands/release_management_commands.py:2021:5: PLR0912 Too many branches (23 > 12)
+ dev/breeze/src/airflow_breeze/commands/release_management_commands.py:3277:5: PLR0912 Too many branches (19 > 12)
... 7 additional changes omitted for project

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

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

- src/bokeh/command/subcommands/serve.py:802:9: PLR0912 Too many branches (25 > 12)
+ src/bokeh/command/subcommands/serve.py:802:9: PLR0912 Too many branches (31 > 12)
- src/bokeh/embed/bundle.py:259:5: PLR0912 Too many branches (15 > 12)
+ src/bokeh/embed/bundle.py:259:5: PLR0912 Too many branches (17 > 12)

zulip/zulip (+14 -8 violations, +0 -0 fixes)

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

+ corporate/lib/stripe.py:1700:9: PLR0912 Too many branches (19 > 12)
- corporate/lib/stripe.py:2770:9: PLR0912 Too many branches (27 > 12)
+ corporate/lib/stripe.py:2770:9: PLR0912 Too many branches (28 > 12)
- zerver/actions/create_realm.py:155:5: PLR0912 Too many branches (19 > 12)
+ zerver/actions/create_realm.py:155:5: PLR0912 Too many branches (22 > 12)
- zerver/actions/message_send.py:846:5: PLR0912 Too many branches (29 > 12)
+ zerver/actions/message_send.py:846:5: PLR0912 Too many branches (34 > 12)
+ zerver/actions/scheduled_messages.py:129:5: PLR0912 Too many branches (18 > 12)
- zerver/lib/import_realm.py:775:5: PLR0912 Too many branches (32 > 12)
+ zerver/lib/import_realm.py:775:5: PLR0912 Too many branches (33 > 12)
- zerver/lib/import_realm.py:966:5: PLR0912 Too many branches (38 > 12)
+ zerver/lib/import_realm.py:966:5: PLR0912 Too many branches (48 > 12)
+ zerver/lib/push_notifications.py:1267:5: PLR0912 Too many branches (17 > 12)
- zerver/management/commands/export_search.py:101:9: PLR0912 Too many branches (17 > 12)
+ zerver/management/commands/export_search.py:101:9: PLR0912 Too many branches (18 > 12)
+ zerver/views/message_fetch.py:99:5: PLR0912 Too many branches (22 > 12)
+ zerver/views/streams.py:699:5: PLR0912 Too many branches (14 > 12)
+ zerver/worker/base.py:166:9: PLR0912 Too many branches (14 > 12)
... 4 additional changes omitted for project

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
PLR0912 61 45 16 0 0

Linter (preview)

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

apache/airflow (+29 -6 violations, +0 -0 fixes)

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

- airflow/cli/commands/connection_command.py:209:5: PLR0912 Too many branches (17 > 12)
+ airflow/cli/commands/connection_command.py:209:5: PLR0912 Too many branches (19 > 12)
- airflow/cli/commands/task_command.py:404:5: PLR0912 Too many branches (15 > 12)
+ airflow/cli/commands/task_command.py:404:5: PLR0912 Too many branches (16 > 12)
- airflow/cli/commands/task_command.py:631:5: PLR0912 Too many branches (16 > 12)
+ airflow/cli/commands/task_command.py:631:5: PLR0912 Too many branches (18 > 12)
+ airflow/models/dagrun.py:755:9: PLR0912 Too many branches (15 > 12)
+ airflow/models/taskinstance.py:2489:9: PLR0912 Too many branches (24 > 12)
- airflow/models/taskinstance.py:400:5: PLR0912 Too many branches (14 > 12)
+ airflow/models/taskinstance.py:400:5: PLR0912 Too many branches (22 > 12)
+ airflow/providers/apache/hive/transfers/s3_to_hive.py:141:9: PLR0912 Too many branches (17 > 12)
+ airflow/providers/apache/livy/hooks/livy.py:496:15: PLR0912 Too many branches (16 > 12)
+ airflow/providers/cncf/kubernetes/executors/kubernetes_executor.py:213:9: PLR0912 Too many branches (16 > 12)
+ airflow/providers/cncf/kubernetes/executors/kubernetes_executor.py:379:9: PLR0912 Too many branches (17 > 12)
+ airflow/providers/common/sql/hooks/sql.py:356:9: PLR0912 Too many branches (14 > 12)
+ airflow/providers/databricks/hooks/databricks_sql.py:199:9: PLR0912 Too many branches (16 > 12)
+ airflow/providers/databricks/operators/databricks_sql.py:126:9: PLR0912 Too many branches (13 > 12)
+ airflow/providers/elasticsearch/log/es_task_handler.py:216:9: PLR0912 Too many branches (14 > 12)
+ airflow/providers/exasol/hooks/exasol.py:187:9: PLR0912 Too many branches (14 > 12)
+ airflow/providers/google/cloud/operators/gcs.py:792:9: PLR0912 Too many branches (20 > 12)
+ airflow/providers/http/hooks/http.py:318:15: PLR0912 Too many branches (24 > 12)
+ airflow/providers/openlineage/utils/utils.py:305:9: PLR0912 Too many branches (13 > 12)
+ airflow/providers/snowflake/hooks/snowflake.py:340:9: PLR0912 Too many branches (14 > 12)
+ airflow/utils/db.py:1554:5: PLR0912 Too many branches (16 > 12)
+ airflow/www/views.py:3424:9: PLR0912 Too many branches (13 > 12)
+ airflow/www/views.py:739:9: PLR0912 Too many branches (36 > 12)
+ dev/breeze/src/airflow_breeze/commands/release_management_commands.py:2021:5: PLR0912 Too many branches (23 > 12)
+ dev/breeze/src/airflow_breeze/commands/release_management_commands.py:3277:5: PLR0912 Too many branches (19 > 12)
... 7 additional changes omitted for project

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

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

- src/bokeh/command/subcommands/serve.py:802:9: PLR0912 Too many branches (25 > 12)
+ src/bokeh/command/subcommands/serve.py:802:9: PLR0912 Too many branches (31 > 12)
- src/bokeh/embed/bundle.py:259:5: PLR0912 Too many branches (15 > 12)
+ src/bokeh/embed/bundle.py:259:5: PLR0912 Too many branches (17 > 12)

zulip/zulip (+14 -8 violations, +0 -0 fixes)

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

+ corporate/lib/stripe.py:1700:9: PLR0912 Too many branches (19 > 12)
- corporate/lib/stripe.py:2770:9: PLR0912 Too many branches (27 > 12)
+ corporate/lib/stripe.py:2770:9: PLR0912 Too many branches (28 > 12)
- zerver/actions/create_realm.py:155:5: PLR0912 Too many branches (19 > 12)
+ zerver/actions/create_realm.py:155:5: PLR0912 Too many branches (22 > 12)
- zerver/actions/message_send.py:846:5: PLR0912 Too many branches (29 > 12)
+ zerver/actions/message_send.py:846:5: PLR0912 Too many branches (34 > 12)
+ zerver/actions/scheduled_messages.py:129:5: PLR0912 Too many branches (18 > 12)
- zerver/lib/import_realm.py:775:5: PLR0912 Too many branches (32 > 12)
+ zerver/lib/import_realm.py:775:5: PLR0912 Too many branches (33 > 12)
- zerver/lib/import_realm.py:966:5: PLR0912 Too many branches (38 > 12)
+ zerver/lib/import_realm.py:966:5: PLR0912 Too many branches (48 > 12)
+ zerver/lib/push_notifications.py:1267:5: PLR0912 Too many branches (17 > 12)
- zerver/management/commands/export_search.py:101:9: PLR0912 Too many branches (17 > 12)
+ zerver/management/commands/export_search.py:101:9: PLR0912 Too many branches (18 > 12)
+ zerver/views/message_fetch.py:99:5: PLR0912 Too many branches (22 > 12)
+ zerver/views/streams.py:699:5: PLR0912 Too many branches (14 > 12)
+ zerver/worker/base.py:166:9: PLR0912 Too many branches (14 > 12)
... 4 additional changes omitted for project

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
PLR0912 61 45 16 0 0

Copy link
Member

Choose a reason for hiding this comment

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

Can you include additional test cases in this file for with statements? They will be at the bottom of this file and they specifically tests the num_branches function.

@dhruvmanila dhruvmanila added the bug Something isn't working label May 7, 2024
@dhruvmanila
Copy link
Member

Thank you for working on this! Welcome to Ruff :)

@charliermarsh charliermarsh enabled auto-merge (squash) May 8, 2024 03:05
@charliermarsh charliermarsh merged commit 8591adb into astral-sh:main May 8, 2024
19 checks passed
@blueraft blueraft deleted the with-statements-too-many-branches branch May 8, 2024 08:19
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PLR0912: branches inside with statement not counted
4 participants