-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
harupy
wants to merge
4
commits into
astral-sh:main
Choose a base branch
from
harupy:RUF036-autofix
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+331
−20
Open
Changes from 3 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,58 +2,148 @@ | |
source: crates/ruff_linter/src/rules/ruff/mod.rs | ||
snapshot_kind: text | ||
--- | ||
RUF036.py:4:16: RUF036 `None` not at the end of the type annotation. | ||
RUF036.py:4:16: RUF036 [*] `None` not at the end of the type annotation. | ||
| | ||
4 | def func1(arg: None | int): | ||
| ^^^^ RUF036 | ||
5 | ... | ||
| | ||
= help: Move `None` to the end of the type annotation | ||
|
||
RUF036.py:8:16: RUF036 `None` not at the end of the type annotation. | ||
ℹ Safe fix | ||
1 1 | from typing import Union as U | ||
2 2 | | ||
3 3 | | ||
4 |-def func1(arg: None | int): | ||
4 |+def func1(arg: int | None): | ||
5 5 | ... | ||
6 6 | | ||
7 7 | | ||
|
||
RUF036.py:8:16: RUF036 [*] `None` not at the end of the type annotation. | ||
| | ||
8 | def func2() -> None | int: | ||
| ^^^^ RUF036 | ||
9 | ... | ||
| | ||
= help: Move `None` to the end of the type annotation | ||
|
||
ℹ Safe fix | ||
5 5 | ... | ||
6 6 | | ||
7 7 | | ||
8 |-def func2() -> None | int: | ||
8 |+def func2() -> int | None: | ||
9 9 | ... | ||
10 10 | | ||
11 11 | | ||
|
||
RUF036.py:12:16: RUF036 `None` not at the end of the type annotation. | ||
| | ||
12 | def func3(arg: None | None | int): | ||
| ^^^^ RUF036 | ||
13 | ... | ||
| | ||
= help: Move `None` to the end of the type annotation | ||
|
||
RUF036.py:12:23: RUF036 `None` not at the end of the type annotation. | ||
RUF036.py:12:23: RUF036 [*] `None` not at the end of the type annotation. | ||
| | ||
12 | def func3(arg: None | None | int): | ||
| ^^^^ RUF036 | ||
13 | ... | ||
| | ||
= help: Move `None` to the end of the type annotation | ||
|
||
ℹ Safe fix | ||
9 9 | ... | ||
10 10 | | ||
11 11 | | ||
12 |-def func3(arg: None | None | int): | ||
12 |+def func3(arg: int | None): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should avoid removing duplicate |
||
13 13 | ... | ||
14 14 | | ||
15 15 | | ||
|
||
RUF036.py:16:18: RUF036 `None` not at the end of the type annotation. | ||
RUF036.py:16:18: RUF036 [*] `None` not at the end of the type annotation. | ||
| | ||
16 | def func4(arg: U[None, int]): | ||
| ^^^^ RUF036 | ||
17 | ... | ||
| | ||
= help: Move `None` to the end of the type annotation | ||
|
||
RUF036.py:20:18: RUF036 `None` not at the end of the type annotation. | ||
ℹ Safe fix | ||
13 13 | ... | ||
14 14 | | ||
15 15 | | ||
16 |-def func4(arg: U[None, int]): | ||
16 |+def func4(arg: U[int, None]): | ||
17 17 | ... | ||
18 18 | | ||
19 19 | | ||
|
||
RUF036.py:20:18: RUF036 [*] `None` not at the end of the type annotation. | ||
| | ||
20 | def func5() -> U[None, int]: | ||
| ^^^^ RUF036 | ||
21 | ... | ||
| | ||
= help: Move `None` to the end of the type annotation | ||
|
||
ℹ Safe fix | ||
17 17 | ... | ||
18 18 | | ||
19 19 | | ||
20 |-def func5() -> U[None, int]: | ||
20 |+def func5() -> U[int, None]: | ||
21 21 | ... | ||
22 22 | | ||
23 23 | | ||
|
||
RUF036.py:24:18: RUF036 `None` not at the end of the type annotation. | ||
| | ||
24 | def func6(arg: U[None, None, int]): | ||
| ^^^^ RUF036 | ||
25 | ... | ||
| | ||
= help: Move `None` to the end of the type annotation | ||
|
||
RUF036.py:24:24: RUF036 `None` not at the end of the type annotation. | ||
RUF036.py:24:24: RUF036 [*] `None` not at the end of the type annotation. | ||
| | ||
24 | def func6(arg: U[None, None, int]): | ||
| ^^^^ RUF036 | ||
25 | ... | ||
| | ||
= help: Move `None` to the end of the type annotation | ||
|
||
ℹ Safe fix | ||
21 21 | ... | ||
22 22 | | ||
23 23 | | ||
24 |-def func6(arg: U[None, None, int]): | ||
24 |+def func6(arg: U[int, None]): | ||
25 25 | ... | ||
26 26 | | ||
27 27 | | ||
|
||
RUF036.py:29:5: RUF036 [*] `None` not at the end of the type annotation. | ||
| | ||
28 | def func7() -> U[ | ||
29 | None, | ||
| ^^^^ RUF036 | ||
30 | # comment | ||
31 | int | ||
| | ||
= help: Move `None` to the end of the type annotation | ||
|
||
ℹ Unsafe fix | ||
26 26 | | ||
27 27 | | ||
28 28 | def func7() -> U[ | ||
29 |- None, | ||
30 |- # comment | ||
31 |- int | ||
29 |+ int, None | ||
32 30 | ]: | ||
33 31 | ... | ||
34 32 | |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you tell me a bit more why you think we should (or shouldn't) set the fix for all violations?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MichaReiser For example, this part looks like the same fix is set to all the diagnostics:
ruff/crates/ruff_linter/src/rules/flake8_pyi/rules/duplicate_union_member.rs
Lines 126 to 129 in 8b9c843
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm actually leaning towards only emitting a single diagnostic rather than emitting multiple diagnostics. This should also simplify the code a bit because we can change
none_exprs
to anOption
only tracking thelast_none
rather than allNone
valuesThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A single diagnostic makes sense.