Skip to content
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 type annotations in string-or-bytes-too-long (PYI053) #13002

Merged
merged 3 commits into from
Aug 20, 2024

Conversation

dylwil3
Copy link
Collaborator

@dylwil3 dylwil3 commented Aug 20, 2024

PYI053 is meant to protect against default arguments being too lengthy, not, e.g., type annotations with long literal strings.

Closes #12995

@dylwil3 dylwil3 requested a review from AlexWaygood as a code owner August 20, 2024 03:31
Copy link
Contributor

ruff-ecosystem results

Linter (stable)

ℹ️ ecosystem check detected linter changes. (+0 -14 violations, +0 -0 fixes in 1 projects; 53 projects unchanged)

python/typeshed (+0 -14 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --no-preview --select E,F,FA,I,PYI,RUF,UP,W

- stubs/tensorflow/tensorflow/compiler/xla/xla_pb2.pyi:1188:11052: PYI062 Duplicate literal member `...`
- stubs/tensorflow/tensorflow/compiler/xla/xla_pb2.pyi:1188:11057: PYI062 Duplicate literal member `...`
- stubs/tensorflow/tensorflow/compiler/xla/xla_pb2.pyi:1188:11062: PYI062 Duplicate literal member `...`
- stubs/tensorflow/tensorflow/compiler/xla/xla_pb2.pyi:1188:11067: PYI062 Duplicate literal member `...`
- stubs/tensorflow/tensorflow/compiler/xla/xla_pb2.pyi:1188:3422: PYI062 Duplicate literal member `...`
- stubs/tensorflow/tensorflow/compiler/xla/xla_pb2.pyi:1188:5868: PYI062 Duplicate literal member `...`
- stubs/tensorflow/tensorflow/compiler/xla/xla_pb2.pyi:1188:5873: PYI062 Duplicate literal member `...`
- stubs/tensorflow/tensorflow/compiler/xla/xla_pb2.pyi:1188:8355: PYI062 Duplicate literal member `...`
- stubs/tensorflow/tensorflow/compiler/xla/xla_pb2.pyi:1188:8360: PYI062 Duplicate literal member `...`
- stubs/tensorflow/tensorflow/compiler/xla/xla_pb2.pyi:1188:8689: PYI062 Duplicate literal member `...`
- stubs/tensorflow/tensorflow/compiler/xla/xla_pb2.pyi:1188:8694: PYI062 Duplicate literal member `...`
- stubs/tensorflow/tensorflow/core/protobuf/rewriter_config_pb2.pyi:496:918: PYI062 Duplicate literal member `...`
- stubs/tensorflow/tensorflow/core/protobuf/rewriter_config_pb2.pyi:496:923: PYI062 Duplicate literal member `...`
- stubs/tensorflow/tensorflow/core/protobuf/rewriter_config_pb2.pyi:496:928: PYI062 Duplicate literal member `...`

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
PYI062 14 0 14 0 0

Linter (preview)

ℹ️ ecosystem check detected linter changes. (+0 -14 violations, +0 -0 fixes in 1 projects; 53 projects unchanged)

python/typeshed (+0 -14 violations, +0 -0 fixes)

ruff check --no-cache --exit-zero --ignore RUF9 --output-format concise --preview --select E,F,FA,I,PYI,RUF,UP,W

- stubs/tensorflow/tensorflow/compiler/xla/xla_pb2.pyi:1188:11052: PYI062 Duplicate literal member `...`
- stubs/tensorflow/tensorflow/compiler/xla/xla_pb2.pyi:1188:11057: PYI062 Duplicate literal member `...`
- stubs/tensorflow/tensorflow/compiler/xla/xla_pb2.pyi:1188:11062: PYI062 Duplicate literal member `...`
- stubs/tensorflow/tensorflow/compiler/xla/xla_pb2.pyi:1188:11067: PYI062 Duplicate literal member `...`
- stubs/tensorflow/tensorflow/compiler/xla/xla_pb2.pyi:1188:3422: PYI062 Duplicate literal member `...`
- stubs/tensorflow/tensorflow/compiler/xla/xla_pb2.pyi:1188:5868: PYI062 Duplicate literal member `...`
- stubs/tensorflow/tensorflow/compiler/xla/xla_pb2.pyi:1188:5873: PYI062 Duplicate literal member `...`
- stubs/tensorflow/tensorflow/compiler/xla/xla_pb2.pyi:1188:8355: PYI062 Duplicate literal member `...`
- stubs/tensorflow/tensorflow/compiler/xla/xla_pb2.pyi:1188:8360: PYI062 Duplicate literal member `...`
- stubs/tensorflow/tensorflow/compiler/xla/xla_pb2.pyi:1188:8689: PYI062 Duplicate literal member `...`
- stubs/tensorflow/tensorflow/compiler/xla/xla_pb2.pyi:1188:8694: PYI062 Duplicate literal member `...`
- stubs/tensorflow/tensorflow/core/protobuf/rewriter_config_pb2.pyi:496:918: PYI062 Duplicate literal member `...`
- stubs/tensorflow/tensorflow/core/protobuf/rewriter_config_pb2.pyi:496:923: PYI062 Duplicate literal member `...`
- stubs/tensorflow/tensorflow/core/protobuf/rewriter_config_pb2.pyi:496:928: PYI062 Duplicate literal member `...`

Changes by rule (1 rules affected)

code total + violation - violation + fix - fix
PYI062 14 0 14 0 0

Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@@ -59,6 +59,10 @@ pub(crate) fn string_or_bytes_too_long(checker: &mut Checker, string: StringLike
return;
}

if semantic.in_annotation() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wondered if it might be better to be more targeted in our exclusions here, since there are relatively few valid annotations in stub files that would involve long string literals -- basically just Literal and Annotated, I think? We can detect if we're in a typing.Literal slice like this:

Suggested change
if semantic.in_annotation() {
if semantic.in_typing_literal() {

But we don't currently track in the semantic model whether we're in an Annotated slice in the same way, and I'm not sure if it's worth it to add that tracking just for this, as I'm not sure it would practically get us much.

TL;DR -- this seems good; thanks!

@AlexWaygood AlexWaygood added bug Something isn't working rule Implementing or modifying a lint rule labels Aug 20, 2024
@AlexWaygood AlexWaygood changed the title [flake8-pyi] Skip type annotations in string-or-bytes-too-long (PYI053) [flake8-pyi] Skip type annotations in string-or-bytes-too-long (PYI053) Aug 20, 2024
@AlexWaygood AlexWaygood merged commit 9baab86 into astral-sh:main Aug 20, 2024
20 checks passed
@dylwil3 dylwil3 deleted the pyi053-ignore-annotation branch August 20, 2024 10:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working rule Implementing or modifying a lint rule
Projects
None yet
Development

Successfully merging this pull request may close these issues.

string-or-bytes-too-long (PYI053) flags and removes long strings in Literal, producing invalid type
2 participants