Open dscorbett opened 5 hours ago
Thanks so much!
Maybe this logic needs some inspection (or the QuoteAnnotator
's Visitor
implementation)?
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 Callable
, which is a list) as the quoted annotation builder was recursing through the expressions. Gonna check a few more edge cases to see if some other things weren't handled.
But if I miss any I'm counting on you to find a slick example 😂 you're so good at this!
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: