diff --git a/crates/ruff_linter/resources/test/fixtures/flake8_pyi/PYI053.pyi b/crates/ruff_linter/resources/test/fixtures/flake8_pyi/PYI053.pyi index b25a02db20c7b..5cb3585c57760 100644 --- a/crates/ruff_linter/resources/test/fixtures/flake8_pyi/PYI053.pyi +++ b/crates/ruff_linter/resources/test/fixtures/flake8_pyi/PYI053.pyi @@ -67,5 +67,16 @@ def not_a_deprecated_function() -> None: ... fbaz: str = f"51 character {foo} stringgggggggggggggggggggggggggg" # Error: PYI053 +from typing import TypeAlias, Literal, Annotated + # see https://github.com/astral-sh/ruff/issues/12995 -def foo(bar: typing.Literal["a", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"]):... \ No newline at end of file +def foo(bar: typing.Literal["a", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"]):... + +# Ok +def f(x: int) -> "AnnotationsForClassesWithVeryLongNamesInQuotesAsReturnTypes":... + +# Ok +x: TypeAlias = Literal["fooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooO"] + +# Ok +y: TypeAlias = Annotated[int, "metadataaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"] diff --git a/crates/ruff_linter/src/rules/flake8_pyi/rules/string_or_bytes_too_long.rs b/crates/ruff_linter/src/rules/flake8_pyi/rules/string_or_bytes_too_long.rs index 610d7f5d1b73c..5ec88d60fab4d 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/rules/string_or_bytes_too_long.rs +++ b/crates/ruff_linter/src/rules/flake8_pyi/rules/string_or_bytes_too_long.rs @@ -59,7 +59,7 @@ pub(crate) fn string_or_bytes_too_long(checker: &mut Checker, string: StringLike return; } - if semantic.in_annotation() { + if semantic.in_type_definition() | semantic.in_deferred_type_definition() { return; } diff --git a/crates/ruff_linter/src/rules/flake8_pyi/snapshots/ruff_linter__rules__flake8_pyi__tests__PYI053_PYI053.pyi.snap b/crates/ruff_linter/src/rules/flake8_pyi/snapshots/ruff_linter__rules__flake8_pyi__tests__PYI053_PYI053.pyi.snap index bf4d9d6f2cec5..de9bc7be61b72 100644 --- a/crates/ruff_linter/src/rules/flake8_pyi/snapshots/ruff_linter__rules__flake8_pyi__tests__PYI053_PYI053.pyi.snap +++ b/crates/ruff_linter/src/rules/flake8_pyi/snapshots/ruff_linter__rules__flake8_pyi__tests__PYI053_PYI053.pyi.snap @@ -1,6 +1,5 @@ --- source: crates/ruff_linter/src/rules/flake8_pyi/mod.rs -snapshot_kind: text --- PYI053.pyi:7:14: PYI053 [*] String and bytes literals longer than 50 characters are not permitted | @@ -154,7 +153,7 @@ PYI053.pyi:68:13: PYI053 [*] String and bytes literals longer than 50 characters 68 | fbaz: str = f"51 character {foo} stringgggggggggggggggggggggggggg" # Error: PYI053 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PYI053 69 | -70 | # see https://github.com/astral-sh/ruff/issues/12995 +70 | from typing import TypeAlias, Literal, Annotated | = help: Replace with `...` @@ -165,5 +164,5 @@ PYI053.pyi:68:13: PYI053 [*] String and bytes literals longer than 50 characters 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"]):... +70 70 | from typing import TypeAlias, Literal, Annotated +71 71 |