Skip to content

Commit 1bd8fbb

Browse files
authored
[flake8-pyi] Skip all type definitions in string-or-bytes-too-long (PYI053) (#14797)
1 parent b0e26e6 commit 1bd8fbb

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

crates/ruff_linter/resources/test/fixtures/flake8_pyi/PYI053.pyi

+12-1
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,16 @@ def not_a_deprecated_function() -> None: ...
6767

6868
fbaz: str = f"51 character {foo} stringgggggggggggggggggggggggggg" # Error: PYI053
6969

70+
from typing import TypeAlias, Literal, Annotated
71+
7072
# see https://github.com/astral-sh/ruff/issues/12995
71-
def foo(bar: typing.Literal["a", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"]):...
73+
def foo(bar: typing.Literal["a", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"]):...
74+
75+
# Ok
76+
def f(x: int) -> "AnnotationsForClassesWithVeryLongNamesInQuotesAsReturnTypes":...
77+
78+
# Ok
79+
x: TypeAlias = Literal["fooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooO"]
80+
81+
# Ok
82+
y: TypeAlias = Annotated[int, "metadataaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"]

crates/ruff_linter/src/rules/flake8_pyi/rules/string_or_bytes_too_long.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub(crate) fn string_or_bytes_too_long(checker: &mut Checker, string: StringLike
5959
return;
6060
}
6161

62-
if semantic.in_annotation() {
62+
if semantic.in_type_definition() | semantic.in_deferred_type_definition() {
6363
return;
6464
}
6565

crates/ruff_linter/src/rules/flake8_pyi/snapshots/ruff_linter__rules__flake8_pyi__tests__PYI053_PYI053.pyi.snap

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
---
22
source: crates/ruff_linter/src/rules/flake8_pyi/mod.rs
3-
snapshot_kind: text
43
---
54
PYI053.pyi:7:14: PYI053 [*] String and bytes literals longer than 50 characters are not permitted
65
|
@@ -154,7 +153,7 @@ PYI053.pyi:68:13: PYI053 [*] String and bytes literals longer than 50 characters
154153
68 | fbaz: str = f"51 character {foo} stringgggggggggggggggggggggggggg" # Error: PYI053
155154
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PYI053
156155
69 |
157-
70 | # see https://github.com/astral-sh/ruff/issues/12995
156+
70 | from typing import TypeAlias, Literal, Annotated
158157
|
159158
= help: Replace with `...`
160159

@@ -165,5 +164,5 @@ PYI053.pyi:68:13: PYI053 [*] String and bytes literals longer than 50 characters
165164
68 |-fbaz: str = f"51 character {foo} stringgggggggggggggggggggggggggg" # Error: PYI053
166165
68 |+fbaz: str = ... # Error: PYI053
167166
69 69 |
168-
70 70 | # see https://github.com/astral-sh/ruff/issues/12995
169-
71 71 | def foo(bar: typing.Literal["a", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"]):...
167+
70 70 | from typing import TypeAlias, Literal, Annotated
168+
71 71 |

0 commit comments

Comments
 (0)