-
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
[flake8-pyi] Skip Annotated and Literal for string-or-bytes-too-long (PYI053)
#13020
Closed
Closed
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5b80d74
update fixture
dylwil3 7e37dd7
add flag for Annotation
dylwil3 26141b0
turn on flag inside pep593 annotation
dylwil3 e4b2563
update rule
dylwil3 1478fda
update snapshot
dylwil3 00589d4
Merge branch 'main' into pyi053-redux
dylwil3 7c098bd
add link to pep 593
dylwil3 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
228 changes: 114 additions & 114 deletions
228
.../rules/flake8_pyi/snapshots/ruff_linter__rules__flake8_pyi__tests__PYI053_PYI053.pyi.snap
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 |
---|---|---|
@@ -1,168 +1,168 @@ | ||
--- | ||
source: crates/ruff_linter/src/rules/flake8_pyi/mod.rs | ||
--- | ||
PYI053.pyi:7:14: PYI053 [*] String and bytes literals longer than 50 characters are not permitted | ||
| | ||
5 | def f1(x: str = "50 character stringggggggggggggggggggggggggggggggg") -> None: ... # OK | ||
6 | def f2( | ||
7 | x: str = "51 character stringgggggggggggggggggggggggggggggggg", # Error: PYI053 | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PYI053 | ||
8 | ) -> None: ... | ||
9 | def f3( | ||
| | ||
= help: Replace with `...` | ||
PYI053.pyi:8:14: PYI053 [*] String and bytes literals longer than 50 characters are not permitted | ||
| | ||
6 | def f1(x: str = "50 character stringggggggggggggggggggggggggggggggg") -> None: ... # OK | ||
7 | def f2( | ||
8 | x: str = "51 character stringgggggggggggggggggggggggggggggggg", # Error: PYI053 | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PYI053 | ||
9 | ) -> None: ... | ||
10 | def f3( | ||
| | ||
= help: Replace with `...` | ||
|
||
ℹ Safe fix | ||
4 4 | | ||
5 5 | def f1(x: str = "50 character stringggggggggggggggggggggggggggggggg") -> None: ... # OK | ||
6 6 | def f2( | ||
7 |- x: str = "51 character stringgggggggggggggggggggggggggggggggg", # Error: PYI053 | ||
7 |+ x: str = ..., # Error: PYI053 | ||
8 8 | ) -> None: ... | ||
9 9 | def f3( | ||
10 10 | x: str = "50 character stringgggggggggggggggggggggggggggggg\U0001f600", # OK | ||
5 5 | | ||
6 6 | def f1(x: str = "50 character stringggggggggggggggggggggggggggggggg") -> None: ... # OK | ||
7 7 | def f2( | ||
8 |- x: str = "51 character stringgggggggggggggggggggggggggggggggg", # Error: PYI053 | ||
8 |+ x: str = ..., # Error: PYI053 | ||
9 9 | ) -> None: ... | ||
10 10 | def f3( | ||
11 11 | x: str = "50 character stringgggggggggggggggggggggggggggggg\U0001f600", # OK | ||
|
||
PYI053.pyi:13:14: PYI053 [*] String and bytes literals longer than 50 characters are not permitted | ||
PYI053.pyi:14:14: PYI053 [*] String and bytes literals longer than 50 characters are not permitted | ||
| | ||
11 | ) -> None: ... | ||
12 | def f4( | ||
13 | x: str = "51 character stringggggggggggggggggggggggggggggggg\U0001f600", # Error: PYI053 | ||
12 | ) -> None: ... | ||
13 | def f4( | ||
14 | x: str = "51 character stringggggggggggggggggggggggggggggggg\U0001f600", # Error: PYI053 | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PYI053 | ||
14 | ) -> None: ... | ||
15 | def f5( | ||
15 | ) -> None: ... | ||
16 | def f5( | ||
| | ||
= help: Replace with `...` | ||
|
||
ℹ Safe fix | ||
10 10 | x: str = "50 character stringgggggggggggggggggggggggggggggg\U0001f600", # OK | ||
11 11 | ) -> None: ... | ||
12 12 | def f4( | ||
13 |- x: str = "51 character stringggggggggggggggggggggggggggggggg\U0001f600", # Error: PYI053 | ||
13 |+ x: str = ..., # Error: PYI053 | ||
14 14 | ) -> None: ... | ||
15 15 | def f5( | ||
16 16 | x: bytes = b"50 character byte stringgggggggggggggggggggggggggg", # OK | ||
11 11 | x: str = "50 character stringgggggggggggggggggggggggggggggg\U0001f600", # OK | ||
12 12 | ) -> None: ... | ||
13 13 | def f4( | ||
14 |- x: str = "51 character stringggggggggggggggggggggggggggggggg\U0001f600", # Error: PYI053 | ||
14 |+ x: str = ..., # Error: PYI053 | ||
15 15 | ) -> None: ... | ||
16 16 | def f5( | ||
17 17 | x: bytes = b"50 character byte stringgggggggggggggggggggggggggg", # OK | ||
|
||
PYI053.pyi:25:16: PYI053 [*] String and bytes literals longer than 50 characters are not permitted | ||
PYI053.pyi:26:16: PYI053 [*] String and bytes literals longer than 50 characters are not permitted | ||
| | ||
23 | ) -> None: ... | ||
24 | def f8( | ||
25 | x: bytes = b"51 character byte stringgggggggggggggggggggggggggg\xff", # Error: PYI053 | ||
24 | ) -> None: ... | ||
25 | def f8( | ||
26 | x: bytes = b"51 character byte stringgggggggggggggggggggggggggg\xff", # Error: PYI053 | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PYI053 | ||
26 | ) -> None: ... | ||
27 | ) -> None: ... | ||
| | ||
= help: Replace with `...` | ||
|
||
ℹ Safe fix | ||
22 22 | x: bytes = b"50 character byte stringggggggggggggggggggggggggg\xff", # OK | ||
23 23 | ) -> None: ... | ||
24 24 | def f8( | ||
25 |- x: bytes = b"51 character byte stringgggggggggggggggggggggggggg\xff", # Error: PYI053 | ||
25 |+ x: bytes = ..., # Error: PYI053 | ||
26 26 | ) -> None: ... | ||
27 27 | | ||
28 28 | foo: str = "50 character stringggggggggggggggggggggggggggggggg" # OK | ||
23 23 | x: bytes = b"50 character byte stringggggggggggggggggggggggggg\xff", # OK | ||
24 24 | ) -> None: ... | ||
25 25 | def f8( | ||
26 |- x: bytes = b"51 character byte stringgggggggggggggggggggggggggg\xff", # Error: PYI053 | ||
26 |+ x: bytes = ..., # Error: PYI053 | ||
27 27 | ) -> None: ... | ||
28 28 | | ||
29 29 | foo: str = "50 character stringggggggggggggggggggggggggggggggg" # OK | ||
|
||
PYI053.pyi:30:12: PYI053 [*] String and bytes literals longer than 50 characters are not permitted | ||
PYI053.pyi:31:12: PYI053 [*] String and bytes literals longer than 50 characters are not permitted | ||
| | ||
28 | foo: str = "50 character stringggggggggggggggggggggggggggggggg" # OK | ||
29 | | ||
30 | bar: str = "51 character stringgggggggggggggggggggggggggggggggg" # Error: PYI053 | ||
29 | foo: str = "50 character stringggggggggggggggggggggggggggggggg" # OK | ||
30 | | ||
31 | bar: str = "51 character stringgggggggggggggggggggggggggggggggg" # Error: PYI053 | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PYI053 | ||
31 | | ||
32 | baz: bytes = b"50 character byte stringgggggggggggggggggggggggggg" # OK | ||
32 | | ||
33 | baz: bytes = b"50 character byte stringgggggggggggggggggggggggggg" # OK | ||
| | ||
= help: Replace with `...` | ||
|
||
ℹ Safe fix | ||
27 27 | | ||
28 28 | foo: str = "50 character stringggggggggggggggggggggggggggggggg" # OK | ||
29 29 | | ||
30 |-bar: str = "51 character stringgggggggggggggggggggggggggggggggg" # Error: PYI053 | ||
30 |+bar: str = ... # Error: PYI053 | ||
31 31 | | ||
32 32 | baz: bytes = b"50 character byte stringgggggggggggggggggggggggggg" # OK | ||
33 33 | | ||
28 28 | | ||
29 29 | foo: str = "50 character stringggggggggggggggggggggggggggggggg" # OK | ||
30 30 | | ||
31 |-bar: str = "51 character stringgggggggggggggggggggggggggggggggg" # Error: PYI053 | ||
31 |+bar: str = ... # Error: PYI053 | ||
32 32 | | ||
33 33 | baz: bytes = b"50 character byte stringgggggggggggggggggggggggggg" # OK | ||
34 34 | | ||
|
||
PYI053.pyi:34:14: PYI053 [*] String and bytes literals longer than 50 characters are not permitted | ||
PYI053.pyi:35:14: PYI053 [*] String and bytes literals longer than 50 characters are not permitted | ||
| | ||
32 | baz: bytes = b"50 character byte stringgggggggggggggggggggggggggg" # OK | ||
33 | | ||
34 | qux: bytes = b"51 character byte stringggggggggggggggggggggggggggg\xff" # Error: PYI053 | ||
33 | baz: bytes = b"50 character byte stringgggggggggggggggggggggggggg" # OK | ||
34 | | ||
35 | qux: bytes = b"51 character byte stringggggggggggggggggggggggggggg\xff" # Error: PYI053 | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PYI053 | ||
35 | | ||
36 | ffoo: str = f"50 character stringggggggggggggggggggggggggggggggg" # OK | ||
36 | | ||
37 | ffoo: str = f"50 character stringggggggggggggggggggggggggggggggg" # OK | ||
| | ||
= help: Replace with `...` | ||
|
||
ℹ Safe fix | ||
31 31 | | ||
32 32 | baz: bytes = b"50 character byte stringgggggggggggggggggggggggggg" # OK | ||
33 33 | | ||
34 |-qux: bytes = b"51 character byte stringggggggggggggggggggggggggggg\xff" # Error: PYI053 | ||
34 |+qux: bytes = ... # Error: PYI053 | ||
35 35 | | ||
36 36 | ffoo: str = f"50 character stringggggggggggggggggggggggggggggggg" # OK | ||
37 37 | | ||
32 32 | | ||
33 33 | baz: bytes = b"50 character byte stringgggggggggggggggggggggggggg" # OK | ||
34 34 | | ||
35 |-qux: bytes = b"51 character byte stringggggggggggggggggggggggggggg\xff" # Error: PYI053 | ||
35 |+qux: bytes = ... # Error: PYI053 | ||
36 36 | | ||
37 37 | ffoo: str = f"50 character stringggggggggggggggggggggggggggggggg" # OK | ||
38 38 | | ||
|
||
PYI053.pyi:38:13: PYI053 [*] String and bytes literals longer than 50 characters are not permitted | ||
PYI053.pyi:39:13: PYI053 [*] String and bytes literals longer than 50 characters are not permitted | ||
| | ||
36 | ffoo: str = f"50 character stringggggggggggggggggggggggggggggggg" # OK | ||
37 | | ||
38 | fbar: str = f"51 character stringgggggggggggggggggggggggggggggggg" # Error: PYI053 | ||
37 | ffoo: str = f"50 character stringggggggggggggggggggggggggggggggg" # OK | ||
38 | | ||
39 | fbar: str = f"51 character stringgggggggggggggggggggggggggggggggg" # Error: PYI053 | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PYI053 | ||
39 | | ||
40 | class Demo: | ||
40 | | ||
41 | class Demo: | ||
| | ||
= help: Replace with `...` | ||
|
||
ℹ Safe fix | ||
35 35 | | ||
36 36 | ffoo: str = f"50 character stringggggggggggggggggggggggggggggggg" # OK | ||
37 37 | | ||
38 |-fbar: str = f"51 character stringgggggggggggggggggggggggggggggggg" # Error: PYI053 | ||
38 |+fbar: str = ... # Error: PYI053 | ||
39 39 | | ||
40 40 | class Demo: | ||
41 41 | """Docstrings are excluded from this rule. Some padding.""" # OK | ||
36 36 | | ||
37 37 | ffoo: str = f"50 character stringggggggggggggggggggggggggggggggg" # OK | ||
38 38 | | ||
39 |-fbar: str = f"51 character stringgggggggggggggggggggggggggggggggg" # Error: PYI053 | ||
39 |+fbar: str = ... # Error: PYI053 | ||
40 40 | | ||
41 41 | class Demo: | ||
42 42 | """Docstrings are excluded from this rule. Some padding.""" # OK | ||
|
||
PYI053.pyi:64:5: PYI053 [*] String and bytes literals longer than 50 characters are not permitted | ||
PYI053.pyi:65:5: PYI053 [*] String and bytes literals longer than 50 characters are not permitted | ||
| | ||
63 | @not_warnings_dot_deprecated( | ||
64 | "Not warnings.deprecated, so this one *should* lead to PYI053 in a stub!" # Error: PYI053 | ||
64 | @not_warnings_dot_deprecated( | ||
65 | "Not warnings.deprecated, so this one *should* lead to PYI053 in a stub!" # Error: PYI053 | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PYI053 | ||
65 | ) | ||
66 | def not_a_deprecated_function() -> None: ... | ||
66 | ) | ||
67 | def not_a_deprecated_function() -> None: ... | ||
| | ||
= help: Replace with `...` | ||
|
||
ℹ Safe fix | ||
61 61 | ) -> Callable[[Callable[[], None]], Callable[[], None]]: ... | ||
62 62 | | ||
63 63 | @not_warnings_dot_deprecated( | ||
64 |- "Not warnings.deprecated, so this one *should* lead to PYI053 in a stub!" # Error: PYI053 | ||
64 |+ ... # Error: PYI053 | ||
65 65 | ) | ||
66 66 | def not_a_deprecated_function() -> None: ... | ||
67 67 | | ||
62 62 | ) -> Callable[[Callable[[], None]], Callable[[], None]]: ... | ||
63 63 | | ||
64 64 | @not_warnings_dot_deprecated( | ||
65 |- "Not warnings.deprecated, so this one *should* lead to PYI053 in a stub!" # Error: PYI053 | ||
65 |+ ... # Error: PYI053 | ||
66 66 | ) | ||
67 67 | def not_a_deprecated_function() -> None: ... | ||
68 68 | | ||
|
||
PYI053.pyi:68:13: PYI053 [*] String and bytes literals longer than 50 characters are not permitted | ||
PYI053.pyi:69:13: PYI053 [*] String and bytes literals longer than 50 characters are not permitted | ||
| | ||
66 | def not_a_deprecated_function() -> None: ... | ||
67 | | ||
68 | fbaz: str = f"51 character {foo} stringgggggggggggggggggggggggggg" # Error: PYI053 | ||
67 | def not_a_deprecated_function() -> None: ... | ||
68 | | ||
69 | fbaz: str = f"51 character {foo} stringgggggggggggggggggggggggggg" # Error: PYI053 | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PYI053 | ||
69 | | ||
70 | # see https://github.com/astral-sh/ruff/issues/12995 | ||
70 | | ||
71 | # See https://github.com/astral-sh/ruff/issues/12995 | ||
| | ||
= help: Replace with `...` | ||
|
||
ℹ Safe fix | ||
65 65 | ) | ||
66 66 | def not_a_deprecated_function() -> None: ... | ||
67 67 | | ||
68 |-fbaz: str = f"51 character {foo} stringgggggggggggggggggggggggggg" # Error: PYI053 | ||
68 |+fbaz: str = ... # Error: PYI053 | ||
69 69 | | ||
70 70 | # see https://github.com/astral-sh/ruff/issues/12995 | ||
71 71 | def foo(bar: typing.Literal["a", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"]):... | ||
66 66 | ) | ||
67 67 | def not_a_deprecated_function() -> None: ... | ||
68 68 | | ||
69 |-fbaz: str = f"51 character {foo} stringgggggggggggggggggggggggggg" # Error: PYI053 | ||
69 |+fbaz: str = ... # Error: PYI053 | ||
70 70 | | ||
71 71 | # See https://github.com/astral-sh/ruff/issues/12995 | ||
72 72 | def foo(bar: Literal["a", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"]):... #OK |
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
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.
oof... but I have been trying to think of a better name for 10 minutes and I've got nothing 😆
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.
Seems like a reasonable name given other variants although I leave this up to you to decide, maybe you come up with a better name in the morning ;)
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.
Aside, it would be useful to provide a link to PEP 593 in the documentation above @dylwil3