-
Notifications
You must be signed in to change notification settings - Fork 2.3k
[pyupgrade] Enable rule triggering for stub files (UP043)
#20027
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
59 changes: 59 additions & 0 deletions
59
crates/ruff_linter/resources/test/fixtures/pyupgrade/UP043.pyi
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| from collections.abc import Generator, AsyncGenerator | ||
|
|
||
|
|
||
| def func() -> Generator[int, None, None]: | ||
| yield 42 | ||
|
|
||
|
|
||
| def func() -> Generator[int, None]: | ||
| yield 42 | ||
|
|
||
|
|
||
| def func() -> Generator[int]: | ||
| yield 42 | ||
|
|
||
|
|
||
| def func() -> Generator[int, int, int]: | ||
| foo = yield 42 | ||
| return foo | ||
|
|
||
|
|
||
| def func() -> Generator[int, int, None]: | ||
| _ = yield 42 | ||
| return None | ||
|
|
||
|
|
||
| def func() -> Generator[int, None, int]: | ||
| yield 42 | ||
| return 42 | ||
|
|
||
|
|
||
| async def func() -> AsyncGenerator[int, None]: | ||
| yield 42 | ||
|
|
||
|
|
||
| async def func() -> AsyncGenerator[int]: | ||
| yield 42 | ||
|
|
||
|
|
||
| async def func() -> AsyncGenerator[int, int]: | ||
| foo = yield 42 | ||
| return foo | ||
|
|
||
|
|
||
| from typing import Generator, AsyncGenerator | ||
|
|
||
|
|
||
| def func() -> Generator[str, None, None]: | ||
| yield "hello" | ||
|
|
||
|
|
||
| async def func() -> AsyncGenerator[str, None]: | ||
| yield "hello" | ||
|
|
||
|
|
||
| async def func() -> AsyncGenerator[ # type: ignore | ||
| str, | ||
| None | ||
| ]: | ||
| yield "hello" |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
128 changes: 128 additions & 0 deletions
128
...c/rules/pyupgrade/snapshots/ruff_linter__rules__pyupgrade__tests__UP043.pyi__preview.snap
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| --- | ||
| source: crates/ruff_linter/src/rules/pyupgrade/mod.rs | ||
| --- | ||
| UP043 [*] Unnecessary default type arguments | ||
| --> UP043.pyi:4:15 | ||
| | | ||
| 4 | def func() -> Generator[int, None, None]: | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| 5 | yield 42 | ||
| | | ||
| help: Remove default type arguments | ||
| 1 | from collections.abc import Generator, AsyncGenerator | ||
| 2 | | ||
| 3 | | ||
| - def func() -> Generator[int, None, None]: | ||
| 4 + def func() -> Generator[int]: | ||
| 5 | yield 42 | ||
| 6 | | ||
| 7 | | ||
|
|
||
| UP043 [*] Unnecessary default type arguments | ||
| --> UP043.pyi:8:15 | ||
| | | ||
| 8 | def func() -> Generator[int, None]: | ||
| | ^^^^^^^^^^^^^^^^^^^^ | ||
| 9 | yield 42 | ||
| | | ||
| help: Remove default type arguments | ||
| 5 | yield 42 | ||
| 6 | | ||
| 7 | | ||
| - def func() -> Generator[int, None]: | ||
| 8 + def func() -> Generator[int]: | ||
| 9 | yield 42 | ||
| 10 | | ||
| 11 | | ||
|
|
||
| UP043 [*] Unnecessary default type arguments | ||
| --> UP043.pyi:21:15 | ||
| | | ||
| 21 | def func() -> Generator[int, int, None]: | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| 22 | _ = yield 42 | ||
| 23 | return None | ||
| | | ||
| help: Remove default type arguments | ||
| 18 | return foo | ||
| 19 | | ||
| 20 | | ||
| - def func() -> Generator[int, int, None]: | ||
| 21 + def func() -> Generator[int, int]: | ||
| 22 | _ = yield 42 | ||
| 23 | return None | ||
| 24 | | ||
|
|
||
| UP043 [*] Unnecessary default type arguments | ||
| --> UP043.pyi:31:21 | ||
| | | ||
| 31 | async def func() -> AsyncGenerator[int, None]: | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| 32 | yield 42 | ||
| | | ||
| help: Remove default type arguments | ||
| 28 | return 42 | ||
| 29 | | ||
| 30 | | ||
| - async def func() -> AsyncGenerator[int, None]: | ||
| 31 + async def func() -> AsyncGenerator[int]: | ||
| 32 | yield 42 | ||
| 33 | | ||
| 34 | | ||
|
|
||
| UP043 [*] Unnecessary default type arguments | ||
| --> UP043.pyi:47:15 | ||
| | | ||
| 47 | def func() -> Generator[str, None, None]: | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| 48 | yield "hello" | ||
| | | ||
| help: Remove default type arguments | ||
| 44 | from typing import Generator, AsyncGenerator | ||
| 45 | | ||
| 46 | | ||
| - def func() -> Generator[str, None, None]: | ||
| 47 + def func() -> Generator[str]: | ||
| 48 | yield "hello" | ||
| 49 | | ||
| 50 | | ||
|
|
||
| UP043 [*] Unnecessary default type arguments | ||
| --> UP043.pyi:51:21 | ||
| | | ||
| 51 | async def func() -> AsyncGenerator[str, None]: | ||
| | ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| 52 | yield "hello" | ||
| | | ||
| help: Remove default type arguments | ||
| 48 | yield "hello" | ||
| 49 | | ||
| 50 | | ||
| - async def func() -> AsyncGenerator[str, None]: | ||
| 51 + async def func() -> AsyncGenerator[str]: | ||
| 52 | yield "hello" | ||
| 53 | | ||
| 54 | | ||
|
|
||
| UP043 [*] Unnecessary default type arguments | ||
| --> UP043.pyi:55:21 | ||
| | | ||
| 55 | async def func() -> AsyncGenerator[ # type: ignore | ||
| | _____________________^ | ||
| 56 | | str, | ||
| 57 | | None | ||
| 58 | | ]: | ||
| | |_^ | ||
| 59 | yield "hello" | ||
| | | ||
| help: Remove default type arguments | ||
| 52 | yield "hello" | ||
| 53 | | ||
| 54 | | ||
| - async def func() -> AsyncGenerator[ # type: ignore | ||
| - str, | ||
| - None | ||
| - ]: | ||
| 55 + async def func() -> AsyncGenerator[str]: | ||
| 56 | yield "hello" | ||
| note: This is an unsafe fix and may change runtime behavior |
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.
Thanks for identifying one of the files from the issue! However, I'd probably lean toward a stripped-down example over including a file verbatim from another project since the specifics of the code aren't really that important. We could even just duplicate
UP043.pyand call itUP043.pyi, I think.