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

[pyupgrade] Handle multiple base classes for PEP 695 generics (UP046) #15659

Draft
wants to merge 3 commits into
base: brent/pep695-generics
Choose a base branch
from

Conversation

ntBre
Copy link
Contributor

@ntBre ntBre commented Jan 21, 2025

Summary

Addresses the second follow up to #15565 in #15642. This was easier than expected by using this cool destructuring syntax I don't think I've used before.

I'll leave it as a draft until #15565 is merged and then update the base branch.

Test Plan

Using an existing test, previously marked as a TODO.

@ntBre ntBre added the rule Implementing or modifying a lint rule label Jan 21, 2025
Copy link
Contributor

github-actions bot commented Jan 21, 2025

ruff-ecosystem results

Linter (stable)

ℹ️ ecosystem check detected linter changes. (+171 -171 violations, +30 -0 fixes in 4 projects; 51 projects unchanged)

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

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

- airflow/models/baseoperator.py:168:38: SIM201 Use `sentinel != _sentinel` instead of `not sentinel == _sentinel`
+ airflow/models/baseoperator.py:168:38: SIM201 [*] Use `sentinel != _sentinel` instead of `not sentinel == _sentinel`
- airflow/models/dag.py:822:44: SIM201 Use `ti.state != State.NONE` instead of `not ti.state == State.NONE`
+ airflow/models/dag.py:822:44: SIM201 [*] Use `ti.state != State.NONE` instead of `not ti.state == State.NONE`
- airflow/www/views.py:5625:12: SIM201 Use `os.environ.get("AIRFLOW_ENV", None) != "development"` instead of `not os.environ.get("AIRFLOW_ENV", None) == "development"`
+ airflow/www/views.py:5625:12: SIM201 [*] Use `os.environ.get("AIRFLOW_ENV", None) != "development"` instead of `not os.environ.get("AIRFLOW_ENV", None) == "development"`
- dev/breeze/src/airflow_breeze/params/shell_params.py:358:35: SIM201 Use `self.project_name != "pre-commit"` instead of `not self.project_name == "pre-commit"`
+ dev/breeze/src/airflow_breeze/params/shell_params.py:358:35: SIM201 [*] Use `self.project_name != "pre-commit"` instead of `not self.project_name == "pre-commit"`
- dev/breeze/src/airflow_breeze/params/shell_params.py:708:17: SIM201 Use `self.backend != POSTGRES_BACKEND` instead of `not self.backend == POSTGRES_BACKEND`
+ dev/breeze/src/airflow_breeze/params/shell_params.py:708:17: SIM201 [*] Use `self.backend != POSTGRES_BACKEND` instead of `not self.backend == POSTGRES_BACKEND`
... 16 additional changes omitted for project

binary-husky/gpt_academic (+166 -166 violations, +0 -0 fixes)

+ check_proxy.py:119:1: I001 [*] Import block is un-sorted or un-formatted
- check_proxy.py:119:5: I001 [*] Import block is un-sorted or un-formatted
+ check_proxy.py:179:1: I001 [*] Import block is un-sorted or un-formatted
- check_proxy.py:179:9: I001 [*] Import block is un-sorted or un-formatted
+ check_proxy.py:226:1: I001 [*] Import block is un-sorted or un-formatted
- check_proxy.py:226:5: I001 [*] Import block is un-sorted or un-formatted
+ check_proxy.py:57:1: I001 [*] Import block is un-sorted or un-formatted
- check_proxy.py:57:5: I001 [*] Import block is un-sorted or un-formatted
+ check_proxy.py:76:1: I001 [*] Import block is un-sorted or un-formatted
- check_proxy.py:76:5: I001 [*] Import block is un-sorted or un-formatted
+ crazy_functional.py:6:1: I001 [*] Import block is un-sorted or un-formatted
- crazy_functional.py:6:5: I001 [*] Import block is un-sorted or un-formatted
+ crazy_functions/Conversation_To_File.py:11:1: I001 [*] Import block is un-sorted or un-formatted
- crazy_functions/Conversation_To_File.py:11:5: I001 [*] Import block is un-sorted or un-formatted
+ crazy_functions/Conversation_To_File.py:210:1: I001 [*] Import block is un-sorted or un-formatted
- crazy_functions/Conversation_To_File.py:210:5: I001 [*] Import block is un-sorted or un-formatted
+ crazy_functions/Image_Generate.py:159:1: I001 [*] Import block is un-sorted or un-formatted
- crazy_functions/Image_Generate.py:159:9: I001 [*] Import block is un-sorted or un-formatted
+ crazy_functions/Image_Generate.py:50:1: I001 [*] Import block is un-sorted or un-formatted
- crazy_functions/Image_Generate.py:50:5: I001 [*] Import block is un-sorted or un-formatted
+ crazy_functions/Image_Generate.py:6:1: I001 [*] Import block is un-sorted or un-formatted
- crazy_functions/Image_Generate.py:6:5: I001 [*] Import block is un-sorted or un-formatted
+ crazy_functions/Latex_Function.py:266:1: I001 [*] Import block is un-sorted or un-formatted
- crazy_functions/Latex_Function.py:266:9: I001 [*] Import block is un-sorted or un-formatted
+ crazy_functions/Latex_Function.py:354:1: I001 [*] Import block is un-sorted or un-formatted
- crazy_functions/Latex_Function.py:354:9: I001 [*] Import block is un-sorted or un-formatted
- crazy_functions/Latex_Function.py:431:13: I001 [*] Import block is un-sorted or un-formatted
+ crazy_functions/Latex_Function.py:431:1: I001 [*] Import block is un-sorted or un-formatted
+ crazy_functions/Latex_Function.py:471:1: I001 [*] Import block is un-sorted or un-formatted
- crazy_functions/Latex_Function.py:471:9: I001 [*] Import block is un-sorted or un-formatted
+ crazy_functions/Latex_Function.py:70:1: I001 [*] Import block is un-sorted or un-formatted
- crazy_functions/Latex_Function.py:70:5: I001 [*] Import block is un-sorted or un-formatted
+ crazy_functions/Latex_Project_Polish.py:155:1: I001 [*] Import block is un-sorted or un-formatted
- crazy_functions/Latex_Project_Polish.py:155:5: I001 [*] Import block is un-sorted or un-formatted
+ crazy_functions/Latex_Project_Polish.py:193:1: I001 [*] Import block is un-sorted or un-formatted
- crazy_functions/Latex_Project_Polish.py:193:5: I001 [*] Import block is un-sorted or un-formatted
+ crazy_functions/Latex_Project_Polish.py:229:1: I001 [*] Import block is un-sorted or un-formatted
- crazy_functions/Latex_Project_Polish.py:229:5: I001 [*] Import block is un-sorted or un-formatted
- crazy_functions/Latex_Project_Polish.py:29:17: I001 [*] Import block is un-sorted or un-formatted
+ crazy_functions/Latex_Project_Polish.py:29:1: I001 [*] Import block is un-sorted or un-formatted
+ crazy_functions/Latex_Project_Polish.py:51:1: I001 [*] Import block is un-sorted or un-formatted
- crazy_functions/Latex_Project_Polish.py:51:9: I001 [*] Import block is un-sorted or un-formatted
+ crazy_functions/Latex_Project_Polish.py:58:1: I001 [*] Import block is un-sorted or un-formatted
- crazy_functions/Latex_Project_Polish.py:58:5: I001 [*] Import block is un-sorted or un-formatted
... 288 additional changes omitted for project

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

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

+ examples/server/app/gapminder/data.py:5:1: I001 [*] Import block is un-sorted or un-formatted
- examples/server/app/gapminder/data.py:5:5: I001 [*] Import block is un-sorted or un-formatted
+ src/bokeh/model/model.py:46:1: I001 [*] Import block is un-sorted or un-formatted
- src/bokeh/model/model.py:46:5: I001 [*] Import block is un-sorted or un-formatted
+ src/bokeh/model/util.py:167:1: I001 [*] Import block is un-sorted or un-formatted
- src/bokeh/model/util.py:167:5: I001 [*] Import block is un-sorted or un-formatted
... 5 additional changes omitted for rule I001
- src/bokeh/server/views/ws.py:168:12: SIM201 Use `len(subprotocols) != 2` instead of `not len(subprotocols) == 2`
+ src/bokeh/server/views/ws.py:168:12: SIM201 [*] Use `len(subprotocols) != 2` instead of `not len(subprotocols) == 2`
... 4 additional changes omitted for project

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

- src/latch_cli/services/sync.py:142:12: SIM201 Use `dest[-1] != "/"` instead of `not dest[-1] == "/"`
+ src/latch_cli/services/sync.py:142:12: SIM201 [*] Use `dest[-1] != "/"` instead of `not dest[-1] == "/"`

Changes by rule (2 rules affected)

code total + violation - violation + fix - fix
I001 342 171 171 0 0
SIM201 30 0 0 30 0

Linter (preview)

ℹ️ ecosystem check detected linter changes. (+179 -193 violations, +30 -0 fixes in 7 projects; 48 projects unchanged)

apache/airflow (+5 -16 violations, +26 -0 fixes)

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

+ airflow/configuration.py:1259:13: SIM103 Return the condition `not value is None` directly
- airflow/configuration.py:1259:13: SIM103 Return the condition `value is not None` directly
- airflow/models/baseoperator.py:168:38: SIM201 Use `sentinel != _sentinel` instead of `not sentinel == _sentinel`
+ airflow/models/baseoperator.py:168:38: SIM201 [*] Use `sentinel != _sentinel` instead of `not sentinel == _sentinel`
- airflow/models/dag.py:822:44: SIM201 Use `ti.state != State.NONE` instead of `not ti.state == State.NONE`
+ airflow/models/dag.py:822:44: SIM201 [*] Use `ti.state != State.NONE` instead of `not ti.state == State.NONE`
- airflow/www/views.py:5625:12: SIM201 Use `os.environ.get("AIRFLOW_ENV", None) != "development"` instead of `not os.environ.get("AIRFLOW_ENV", None) == "development"`
+ airflow/www/views.py:5625:12: SIM201 [*] Use `os.environ.get("AIRFLOW_ENV", None) != "development"` instead of `not os.environ.get("AIRFLOW_ENV", None) == "development"`
... 21 additional changes omitted for rule SIM201
+ providers/src/airflow/providers/amazon/aws/sensors/athena.py:94:9: SIM103 Return the condition `not state in self.INTERMEDIATE_STATES` directly
- providers/src/airflow/providers/amazon/aws/sensors/athena.py:94:9: SIM103 Return the condition `state not in self.INTERMEDIATE_STATES` directly
... 37 additional changes omitted for project

apache/superset (+1 -2 violations, +0 -0 fixes)

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

+ superset/commands/importers/v1/utils.py:204:5: SIM103 Return the condition `not path.suffix.lower() not in {".yaml", ".yml"}` directly
- superset/commands/importers/v1/utils.py:204:5: SIM103 Return the condition `path.suffix.lower() in {".yaml", ".yml"}` directly
- superset/migrations/versions/2023-05-01_12-03_9c2a5681ddfd_convert_key_value_entries_to_json.py:46:27: S301 `pickle` and modules that wrap it can be unsafe when used to deserialize untrusted data, possible security issue

binary-husky/gpt_academic (+166 -166 violations, +0 -0 fixes)

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

+ check_proxy.py:119:1: I001 [*] Import block is un-sorted or un-formatted
- check_proxy.py:119:5: I001 [*] Import block is un-sorted or un-formatted
+ check_proxy.py:179:1: I001 [*] Import block is un-sorted or un-formatted
- check_proxy.py:179:9: I001 [*] Import block is un-sorted or un-formatted
+ check_proxy.py:226:1: I001 [*] Import block is un-sorted or un-formatted
- check_proxy.py:226:5: I001 [*] Import block is un-sorted or un-formatted
+ check_proxy.py:57:1: I001 [*] Import block is un-sorted or un-formatted
- check_proxy.py:57:5: I001 [*] Import block is un-sorted or un-formatted
+ check_proxy.py:76:1: I001 [*] Import block is un-sorted or un-formatted
- check_proxy.py:76:5: I001 [*] Import block is un-sorted or un-formatted
+ crazy_functional.py:6:1: I001 [*] Import block is un-sorted or un-formatted
- crazy_functional.py:6:5: I001 [*] Import block is un-sorted or un-formatted
+ crazy_functions/Conversation_To_File.py:11:1: I001 [*] Import block is un-sorted or un-formatted
- crazy_functions/Conversation_To_File.py:11:5: I001 [*] Import block is un-sorted or un-formatted
+ crazy_functions/Conversation_To_File.py:210:1: I001 [*] Import block is un-sorted or un-formatted
- crazy_functions/Conversation_To_File.py:210:5: I001 [*] Import block is un-sorted or un-formatted
+ crazy_functions/Image_Generate.py:159:1: I001 [*] Import block is un-sorted or un-formatted
- crazy_functions/Image_Generate.py:159:9: I001 [*] Import block is un-sorted or un-formatted
+ crazy_functions/Image_Generate.py:50:1: I001 [*] Import block is un-sorted or un-formatted
- crazy_functions/Image_Generate.py:50:5: I001 [*] Import block is un-sorted or un-formatted
+ crazy_functions/Image_Generate.py:6:1: I001 [*] Import block is un-sorted or un-formatted
- crazy_functions/Image_Generate.py:6:5: I001 [*] Import block is un-sorted or un-formatted
+ crazy_functions/Latex_Function.py:266:1: I001 [*] Import block is un-sorted or un-formatted
- crazy_functions/Latex_Function.py:266:9: I001 [*] Import block is un-sorted or un-formatted
+ crazy_functions/Latex_Function.py:354:1: I001 [*] Import block is un-sorted or un-formatted
- crazy_functions/Latex_Function.py:354:9: I001 [*] Import block is un-sorted or un-formatted
- crazy_functions/Latex_Function.py:431:13: I001 [*] Import block is un-sorted or un-formatted
+ crazy_functions/Latex_Function.py:431:1: I001 [*] Import block is un-sorted or un-formatted
+ crazy_functions/Latex_Function.py:471:1: I001 [*] Import block is un-sorted or un-formatted
- crazy_functions/Latex_Function.py:471:9: I001 [*] Import block is un-sorted or un-formatted
+ crazy_functions/Latex_Function.py:70:1: I001 [*] Import block is un-sorted or un-formatted
- crazy_functions/Latex_Function.py:70:5: I001 [*] Import block is un-sorted or un-formatted
+ crazy_functions/Latex_Project_Polish.py:155:1: I001 [*] Import block is un-sorted or un-formatted
- crazy_functions/Latex_Project_Polish.py:155:5: I001 [*] Import block is un-sorted or un-formatted
+ crazy_functions/Latex_Project_Polish.py:193:1: I001 [*] Import block is un-sorted or un-formatted
- crazy_functions/Latex_Project_Polish.py:193:5: I001 [*] Import block is un-sorted or un-formatted
+ crazy_functions/Latex_Project_Polish.py:229:1: I001 [*] Import block is un-sorted or un-formatted
- crazy_functions/Latex_Project_Polish.py:229:5: I001 [*] Import block is un-sorted or un-formatted
- crazy_functions/Latex_Project_Polish.py:29:17: I001 [*] Import block is un-sorted or un-formatted
+ crazy_functions/Latex_Project_Polish.py:29:1: I001 [*] Import block is un-sorted or un-formatted
+ crazy_functions/Latex_Project_Polish.py:51:1: I001 [*] Import block is un-sorted or un-formatted
... 291 additional changes omitted for project

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

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

+ examples/server/app/gapminder/data.py:5:1: I001 [*] Import block is un-sorted or un-formatted
- examples/server/app/gapminder/data.py:5:5: I001 [*] Import block is un-sorted or un-formatted
+ src/bokeh/model/model.py:46:1: I001 [*] Import block is un-sorted or un-formatted
- src/bokeh/model/model.py:46:5: I001 [*] Import block is un-sorted or un-formatted
+ src/bokeh/model/util.py:167:1: I001 [*] Import block is un-sorted or un-formatted
- src/bokeh/model/util.py:167:5: I001 [*] Import block is un-sorted or un-formatted
... 5 additional changes omitted for rule I001
- src/bokeh/server/views/ws.py:168:12: SIM201 Use `len(subprotocols) != 2` instead of `not len(subprotocols) == 2`
+ src/bokeh/server/views/ws.py:168:12: SIM201 [*] Use `len(subprotocols) != 2` instead of `not len(subprotocols) == 2`
... 4 additional changes omitted for project

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

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

- src/latch_cli/services/sync.py:142:12: SIM201 Use `dest[-1] != "/"` instead of `not dest[-1] == "/"`
+ src/latch_cli/services/sync.py:142:12: SIM201 [*] Use `dest[-1] != "/"` instead of `not dest[-1] == "/"`

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

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

- lnbits/core/crud.py:791:5: RUF047 [*] Empty `else` clause
- lnbits/core/crud.py:800:5: RUF047 [*] Empty `else` clause

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

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

+ zerver/lib/message.py:1539:5: SIM103 Return the condition `not user_profile.realm != message.get_realm()` directly
- zerver/lib/message.py:1539:5: SIM103 Return the condition `user_profile.realm == message.get_realm()` directly
- zerver/views/custom_profile_fields.py:82:5: SIM103 Return the condition `field_data["subtype"] != "custom"` directly
+ zerver/views/custom_profile_fields.py:82:5: SIM103 Return the condition `not field_data["subtype"] == "custom"` directly

Changes by rule (7 rules affected)

code total + violation - violation + fix - fix
I001 342 171 171 0 0
SIM201 30 0 0 30 0
SIM103 16 8 8 0 0
S321 6 0 6 0 0
RUF047 6 0 6 0 0
S307 1 0 1 0 0
S301 1 0 1 0 0

@ntBre ntBre force-pushed the brent/pep695-multi-base branch from 9ff1143 to fcca976 Compare January 22, 2025 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rule Implementing or modifying a lint rule
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant