Repository navigation
Python: type and share the Variable of a *args or **kwargs declaration - #10314
Merged
knutwannheden merged 4 commits intoDec 4, 2026
Merged
Conversation
Python's ast starts a vararg or kwarg parameter at its name, while ty's Parameter node range includes the stars, so the (start, end) lookup missed and the declared identifier got no type and no field type. The parser now passes the star count, and the lookup starts at the stars.
…ration-of-args-and-kwargs
…s uses ty attaches its symbol id to the Parameter node, whose range starts at the stars, so the binding lookup for a star parameter has to use the same star-adjusted range as its type lookup. _shared_variable now takes the binding rather than the node, and each caller looks it up.
ty's parameter node is the one ending where the ast.arg ends and starting nearest before its name, so the range is found from the node index rather than from the name's own line.
knutwannheden
deleted the
python-type-the-declaration-of-args-and-kwargs
branch
December 4, 2026 07:38
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.
In rewrite-python, the declaration of a
*argsor**kwargsparameter got no type and no field type, though its uses inside the function were typed. Fordef g(*args: int): return args, the declaredargshadtypeandfield_typeofNone, while the returnedargswas typedtuple[int, ...].Type and binding lookups are keyed by a node's (start, end) byte range. Python's
ast.argfor a star parameter starts at the name, but ty'sParameternode starts at the stars, so both lookups missed. The binding carries the symbol id that #10313 uses to share oneJavaType.Variablebetween a declaration and its uses.What the change does:
param_type_info._star_param_rangefinds ty's parameter node: the node that ends where theast.argends and starts nearest before its name. It is accepted only when the source at that start is the stars, which also covers a line break or comment between the stars and the name._shared_variabletakes the binding rather than the node, so each caller looks it up at the range that fits.test_a_star_parameters_declaration_shares_the_variable_of_its_usescovers*argsand**kwargs, the latter with a comment and line break after**. It asserts that each declaration's Variable is the same object as its use's field type. It was mutation-checked: it fails when the binding is looked up at the name's own range, and when no range is found.