Skip to content

Consider with statements for too many branches lint - #11321

Merged
charliermarsh merged 4 commits into
astral-sh:mainfrom
blueraft:with-statements-too-many-branches
May 8, 2024
Merged

charliermarsh merged 4 commits into
astral-sh:mainfrom
blueraft:with-statements-too-many-branches

Conversation

@blueraft

@blueraft blueraft commented May 7, 2024

Copy link
Copy Markdown
Contributor

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.

@github-actions

github-actions Bot commented May 7, 2024 •

Copy link
Copy Markdown
Contributor

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

Comment thread crates/ruff_linter/src/rules/pylint/rules/too_many_branches.rs Outdated

Copy link
Copy Markdown
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 An issue describing something that isn't working, or a PR that fixes a bug label May 7, 2024
Comment thread crates/ruff_linter/src/rules/pylint/rules/too_many_branches.rs Outdated
@dhruvmanila

Copy link
Copy Markdown
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
@blueraft
blueraft deleted the with-statements-too-many-branches branch May 8, 2024 08:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug An issue describing something that isn't working, or a PR that fixes a bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PLR0912: branches inside with statement not counted

4 participants