-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
string-or-bytes-too-long (PYI053)
flags and removes long strings in Literal
, producing invalid type
#12995
Comments
string-or-bytes-too-long (PYI053)
flags and removes long strings in Literal
, changing parameter type and producing invalid typestring-or-bytes-too-long (PYI053)
flags and removes long strings in Literal
, producing invalid type
I can actually repro this bug with flake8-pyi as well on this snippet in a from typing import Literal
x: Literal["fooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooO"] We disable the flake8-pyi rule at typeshed for our generated stubs; maybe that's what was hiding the bug? https://github.com/python/typeshed/blob/a7ff1be4394cef089dd62090a2e2ad10cc77cfe6/.flake8#L16 |
I merged #13002, but then immediately afterwards realised that it doesn't deal properly with type aliases. We still get two false positives on this snippet, even after #13002: from typing import TypeAlias, Literal, Annotated
x: TypeAlias = Literal["fooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooO"]
y: TypeAlias = Annotated[int, "metadataaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"] @dylwil3, don't suppose you'd be interested in a followup PR, would you? :-) The alternative approach I suggested in #13002 (comment) might work better here after all:
|
Sounds good I'll give it a try! |
@AlexWaygood Can you not do def f(x: int) --> "AnnotationsForClassesWithVeryLongNamesInQuotesAsReturnTypes" ? |
Well, there's no reason to ever use quoted annotations in stubs, since forward references can be used even with In case it's not obvious, I changed my mind about this while writing this response out 😆 So it's definitely worth adding a comment about this to the code for the rule! |
Hmm... for some reason |
That is odd. I can't immediately see why that would be... don't worry too much about fixing it if you can't figure it out; feel free to ping me if you're stuck! |
Yep, you're right ! That's exactly what happened. |
Sorry for the delay - I was derailed by my baby learning to crawl all of a sudden 🚀 🚀 🚀
Mystery solved - I had an invalid .pyi file since I did not actually import |
In the example reproduction below,
List of keywords you searched for before creating this issue. Write them down here so that others can find this issue more easily and help provide feedback.
string-or-bytes-too-long PYI053
A minimal code snippet that reproduces the bug.
becomes
Not only is this an invalid type form (https://github.com/microsoft/pyright/blob/main/docs/configuration.md#reportInvalidTypeForm) but even if autofixed to
Literal["a"]
that would fundamentally change the parameter's type.I assume this is an oversight as it's meant to replace long default values
and is not flagged by flake8-pyi.The command you invoked (e.g.,
ruff /path/to/file.py --fix
), ideally including the--isolated
flag.ruff check --isolated --select=PYI053
The current Ruff settings (any relevant sections from your
pyproject.toml
).not relevant
The current Ruff version (
ruff --version
).ruff 0.6.1
The text was updated successfully, but these errors were encountered: