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

Autofix for none-not-at-end-of-union (RUF036) #15139

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

Conversation

harupy
Copy link
Contributor

@harupy harupy commented Dec 25, 2024

Summary

Close #15136. Implement autofix for none-not-at-end-of-union (RUF036)

Test Plan

Existing tests

Copy link
Contributor

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

ℹ️ ecosystem check detected linter changes. (+1 -87 violations, +390 -0 fixes in 19 projects; 36 projects unchanged)

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

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

+ tests/test_utils.py:779:25: RUF036 [*] `None` not at the end of the type annotation.
- tests/test_utils.py:779:25: RUF036 `None` not at the end of the type annotation.

RasaHQ/rasa (+0 -0 violations, +6 -0 fixes)

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

+ rasa/shared/core/events.py:597:48: RUF036 [*] `None` not at the end of the type annotation.
- rasa/shared/core/events.py:597:48: RUF036 `None` not at the end of the type annotation.
+ rasa/shared/core/events.py:624:31: RUF036 [*] `None` not at the end of the type annotation.
- rasa/shared/core/events.py:624:31: RUF036 `None` not at the end of the type annotation.
+ rasa/utils/tensorflow/models.py:247:35: RUF036 [*] `None` not at the end of the type annotation.
- rasa/utils/tensorflow/models.py:247:35: RUF036 `None` not at the end of the type annotation.

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

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

+ airflow/api_fastapi/common/parameters.py:641:22: RUF036 [*] `None` not at the end of the type annotation.
- airflow/api_fastapi/common/parameters.py:641:22: RUF036 `None` not at the end of the type annotation.
+ airflow/auth/managers/base_auth_manager.py:448:36: RUF036 [*] `None` not at the end of the type annotation.
- airflow/auth/managers/base_auth_manager.py:448:36: RUF036 `None` not at the end of the type annotation.
+ airflow/cli/commands/remote_commands/task_command.py:250:71: RUF036 [*] `None` not at the end of the type annotation.
- airflow/cli/commands/remote_commands/task_command.py:250:71: RUF036 `None` not at the end of the type annotation.
+ airflow/cli/commands/remote_commands/task_command.py:336:46: RUF036 [*] `None` not at the end of the type annotation.
- airflow/cli/commands/remote_commands/task_command.py:336:46: RUF036 `None` not at the end of the type annotation.
+ airflow/decorators/__init__.pyi:117:23: RUF036 [*] `None` not at the end of the type annotation.
- airflow/decorators/__init__.pyi:117:23: RUF036 `None` not at the end of the type annotation.
+ airflow/decorators/__init__.pyi:118:25: RUF036 [*] `None` not at the end of the type annotation.
- airflow/decorators/__init__.pyi:118:25: RUF036 `None` not at the end of the type annotation.
+ airflow/decorators/__init__.pyi:124:21: RUF036 [*] `None` not at the end of the type annotation.
- airflow/decorators/__init__.pyi:124:21: RUF036 `None` not at the end of the type annotation.
+ airflow/decorators/__init__.pyi:125:26: RUF036 [*] `None` not at the end of the type annotation.
- airflow/decorators/__init__.pyi:125:26: RUF036 `None` not at the end of the type annotation.
+ airflow/decorators/__init__.pyi:245:23: RUF036 [*] `None` not at the end of the type annotation.
- airflow/decorators/__init__.pyi:245:23: RUF036 `None` not at the end of the type annotation.
+ airflow/decorators/__init__.pyi:246:25: RUF036 [*] `None` not at the end of the type annotation.
- airflow/decorators/__init__.pyi:246:25: RUF036 `None` not at the end of the type annotation.
+ airflow/decorators/__init__.pyi:252:21: RUF036 [*] `None` not at the end of the type annotation.
- airflow/decorators/__init__.pyi:252:21: RUF036 `None` not at the end of the type annotation.
+ airflow/decorators/__init__.pyi:253:26: RUF036 [*] `None` not at the end of the type annotation.
- airflow/decorators/__init__.pyi:253:26: RUF036 `None` not at the end of the type annotation.
+ airflow/example_dags/plugins/event_listener.py:93:76: RUF036 [*] `None` not at the end of the type annotation.
... 217 additional changes omitted for project

apache/superset (+0 -0 violations, +10 -0 fixes)

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

+ superset/config.py:1126:5: RUF036 [*] `None` not at the end of the type annotation.
- superset/config.py:1126:5: RUF036 `None` not at the end of the type annotation.
+ superset/config.py:1728:43: RUF036 [*] `None` not at the end of the type annotation.
- superset/config.py:1728:43: RUF036 `None` not at the end of the type annotation.
+ superset/config.py:713:5: RUF036 [*] `None` not at the end of the type annotation.
- superset/config.py:713:5: RUF036 `None` not at the end of the type annotation.
+ superset/db_engine_specs/gsheets.py:166:26: RUF036 [*] `None` not at the end of the type annotation.
- superset/db_engine_specs/gsheets.py:166:26: RUF036 `None` not at the end of the type annotation.
+ superset/jinja_context.py:84:16: RUF036 [*] `None` not at the end of the type annotation.
- superset/jinja_context.py:84:16: RUF036 `None` not at the end of the type annotation.

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

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

+ src/bokeh/client/websocket.py:73:85: RUF036 [*] `None` not at the end of the type annotation.
- src/bokeh/client/websocket.py:73:85: RUF036 `None` not at the end of the type annotation.
+ src/bokeh/embed/standalone.py:84:30: RUF036 [*] `None` not at the end of the type annotation.
- src/bokeh/embed/standalone.py:84:30: RUF036 `None` not at the end of the type annotation.
+ src/bokeh/util/tornado.py:231:26: RUF036 [*] `None` not at the end of the type annotation.
- src/bokeh/util/tornado.py:231:26: RUF036 `None` not at the end of the type annotation.

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

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

+ src/latch/registry/types.py:45:5: RUF036 [*] `None` not at the end of the type annotation.
- src/latch/registry/types.py:45:5: RUF036 `None` not at the end of the type annotation.
+ src/latch/types/metadata.py:419:5: RUF036 [*] `None` not at the end of the type annotation.
- src/latch/types/metadata.py:419:5: RUF036 `None` not at the end of the type annotation.
+ src/latch_cli/services/get.py:38:32: RUF036 [*] `None` not at the end of the type annotation.
- src/latch_cli/services/get.py:38:32: RUF036 `None` not at the end of the type annotation.
+ src/latch_cli/services/launch.py:135:46: RUF036 [*] `None` not at the end of the type annotation.
- src/latch_cli/services/launch.py:135:46: RUF036 `None` not at the end of the type annotation.
+ src/latch_cli/snakemake/config/utils.py:12:53: RUF036 [*] `None` not at the end of the type annotation.
- src/latch_cli/snakemake/config/utils.py:12:53: RUF036 `None` not at the end of the type annotation.
... 4 additional changes omitted for project

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

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

+ lnbits/core/views/payment_api.py:172:27: RUF036 [*] `None` not at the end of the type annotation.
- lnbits/core/views/payment_api.py:172:27: RUF036 `None` not at the end of the type annotation.

milvus-io/pymilvus (+0 -0 violations, +2 -0 fixes)

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

+ pymilvus/client/abstract.py:806:40: RUF036 [*] `None` not at the end of the type annotation.
- pymilvus/client/abstract.py:806:40: RUF036 `None` not at the end of the type annotation.

pandas-dev/pandas (+1 -30 violations, +0 -0 fixes)

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

- pandas/_libs/json.pyi:14:22: RUF036 `None` not at the end of the type annotation.
+ pandas/_libs/json.pyi:14:89: E501 Line too long (91 > 88)
- pandas/core/generic.py:6829:15: RUF036 `None` not at the end of the type annotation.
- pandas/core/generic.py:6831:16: RUF036 `None` not at the end of the type annotation.
- pandas/core/generic.py:7124:15: RUF036 `None` not at the end of the type annotation.
- pandas/core/generic.py:7126:16: RUF036 `None` not at the end of the type annotation.
- pandas/core/generic.py:7134:15: RUF036 `None` not at the end of the type annotation.
... 25 additional changes omitted for rule RUF036
... 24 additional changes omitted for project

pypa/cibuildwheel (+0 -0 violations, +2 -0 fixes)

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

+ cibuildwheel/options.py:753:41: RUF036 [*] `None` not at the end of the type annotation.
- cibuildwheel/options.py:753:41: RUF036 `None` not at the end of the type annotation.

python/typeshed (+0 -54 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview --select E,F,FA,I,PYI,RUF,UP,W

- stdlib/ast.pyi:1726:26: RUF036 `None` not at the end of the type annotation.
- stdlib/ast.pyi:1736:26: RUF036 `None` not at the end of the type annotation.
- stdlib/ast.pyi:1746:26: RUF036 `None` not at the end of the type annotation.
- stdlib/ast.pyi:1756:26: RUF036 `None` not at the end of the type annotation.
- stdlib/ast.pyi:1765:26: RUF036 `None` not at the end of the type annotation.
- stdlib/ast.pyi:1774:26: RUF036 `None` not at the end of the type annotation.
- stdlib/ast.pyi:1783:26: RUF036 `None` not at the end of the type annotation.
- stdlib/ast.pyi:1793:26: RUF036 `None` not at the end of the type annotation.
- stdlib/ast.pyi:1805:26: RUF036 `None` not at the end of the type annotation.
- stdlib/ast.pyi:1814:26: RUF036 `None` not at the end of the type annotation.
... 44 additional changes omitted for project

python-poetry/poetry (+0 -3 violations, +0 -0 fixes)

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

- src/poetry/utils/env/env_manager.py:117:35: RUF036 `None` not at the end of the type annotation.
- src/poetry/utils/env/env_manager.py:142:13: RUF036 `None` not at the end of the type annotation.
- src/poetry/utils/env/env_manager.py:96:44: RUF036 `None` not at the end of the type annotation.

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

Changes by rule (2 rules affected)

code total + violation - violation + fix - fix
RUF036 477 0 87 390 0
E501 1 1 0 0 0

applicability,
)
};
diagnostic.set_fix(fix);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should we set the fix to all the diagnostics?

@AlexWaygood AlexWaygood added the fixes Related to suggested fixes for violations label Dec 25, 2024
@dylwil3
Copy link
Collaborator

dylwil3 commented Dec 25, 2024

Thanks for working on this! Can you add some tests with nested and mixed uses of unions? Like these:

def f(x: None | Union[None ,int]): ...

def g(x: int | (str | None) | list): ...

def h(x: Union[int, Union[None, list | set]]: ...

also the examples from poetry in the ecosystem check like:

    def _detect_active_python(io: None | IO = None) -> Path | None: ...

@dylwil3
Copy link
Collaborator

dylwil3 commented Dec 25, 2024

It looks like in the ecosystem check a bunch of violations were removed with no fix, so I'm wondering if a syntax error was introduced by the fix. Maybe when there is a default argument something goes wrong?

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

Successfully merging this pull request may close these issues.

Feature request: Autofix for none-not-at-end-of-union (RUF036)
3 participants