Read string types in PEP 695/696 positions, skip Literal values and Annotated metadata - #367
Merged
hakancelikdev merged 1 commit intoSep 25, 2026
Conversation
…nnotated metadata - `type X = "Y"`, type parameter bounds and defaults (`def f[T: "Y" = "Z"]`) and TypeVar/ParamSpec/TypeVarTuple `default="Y"` are type expressions, so the imports they name are used. - visit_Subscript parsed every string in a typing subscript, including bare `Literal["os"]` values and `Annotated[T, "meta"]` metadata, which kept unused imports. Literal is skipped and only Annotated's first element is parsed. The function_str_arg case expected the old behavior. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019P9bvuGwAyVCNUdsAYPB1V
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
From the core-dev review of
claude/integration. Follow-up to #344 (issue #329); these cases also exist onmain.Problems
type Money = "Decimal"(PEP 695)def f[T: "Fraction" = "Number"](),class Box[*Ts = "Protocol"](type-param bound and default, PEP 695/696)TypeVar("T", default="Decimal"),ParamSpec("P", default=...),TypeVarTuple(..., default=...)(PEP 696)Literal["os"]kept an unusedimport os.Literalis inSUBSCRIPT_TYPE_VARIABLE, sovisit_Subscriptparsed its strings before the_is_type_expressionguard could run. The guard only worked fort.Literal[...].Annotated[int, "Decimal"]metadata was parsed as a type byvisit_Subscriptin the same way.Fix
_is_type_expressionrecognizesast.TypeAlias.valueand thebound/default_valueofast.TypeVar/ParamSpec/TypeVarTuple. These nodes are looked up withgetattr, since they don't exist on 3.9–3.11.visit_Callreadsdefault=for all three factories. Constraints are still read forTypeVaronly.visit_SubscriptskipsLiteral[...]and parses only the first element ofAnnotated[...].Tests
typing/string_type_parameters(3.13+) andtyping/string_literal_and_defaultsare new. Both fail before this change.typing/function_str_argis regenerated. It asserted the old behavior, where"Literal['Dict']"counted as a use ofDict;'Dict'there is a literal value, soDictis unused.🤖 Generated with Claude Code
https://claude.ai/code/session_019P9bvuGwAyVCNUdsAYPB1V
Generated by Claude Code