-
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
TCH fixes remove quotation marks from Literal
strings
#14368
Comments
Thanks so much! Maybe this logic needs some inspection (or the ruff/crates/ruff_linter/src/rules/flake8_type_checking/helpers.rs Lines 219 to 281 in c847cad
Also appears that the nesting in the type annotation has some effect. For example, this fixes correctly: from collections.abc import Sequence
from typing import Callable, Literal
def f(x: Sequence[Literal["1"]]) -> bool:
return False becomes: from typing import Callable, Literal, TYPE_CHECKING
if TYPE_CHECKING:
from collections.abc import Sequence
def f(x: "Sequence[Literal['1']]") -> bool:
return False |
Looks like the issue was that lists were not handled (i.e. the first argument to But if I miss any I'm counting on you to find a slick example 😂 you're so good at this! |
…ons in quotes (astral-sh#14371) This PR adds corrected handling of list expressions to the `Visitor` implementation of `QuotedAnnotator` in `flake8_type_checking::helpers`. Closes astral-sh#14368
The fixes for TCH001, TCH002, and TCH003 sometimes delete quotation marks from
Literal
s whenlint.flake8-type-checking.quote-annotations = true
. This can make a program fail to type-check. I am not sure exactly what makes it delete quotation marks but it seems to only happen to literals within nested brackets.With
"x"
instead of"1"
in that example,"x"
is rewritten tox
and the final mypy error is:The text was updated successfully, but these errors were encountered: