Skip to content

Commit

Permalink
[flake8-pyi] Skip all type definitions in `string-or-bytes-too-long…
Browse files Browse the repository at this point in the history
… (PYI053)` (#14797)
  • Loading branch information
dylwil3 authored Dec 6, 2024
1 parent b0e26e6 commit 1bd8fbb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
13 changes: 12 additions & 1 deletion crates/ruff_linter/resources/test/fixtures/flake8_pyi/PYI053.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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"]):...
def foo(bar: typing.Literal["a", "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"]):...

# Ok
def f(x: int) -> "AnnotationsForClassesWithVeryLongNamesInQuotesAsReturnTypes":...

# Ok
x: TypeAlias = Literal["fooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooO"]

# Ok
y: TypeAlias = Annotated[int, "metadataaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"]
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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
|
Expand Down Expand Up @@ -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 `...`

Expand All @@ -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 |

0 comments on commit 1bd8fbb

Please sign in to comment.