[red-knot] Move name
field on parameter kind
#16830
Merged
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.
Summary
Previously, the
name
field was onParameter
which required it to be always optional regardless of the parameter kind because atyping.Callable
signature does not have name for the parameters. This is the case for positional-only parameters. This wasn't enforced at the type level which meant that downstream usages would have to unwrap onname
even though it's guaranteed to be present.This commit moves the
name
field fromParameter
to theParameterKind
variants and makes it optional only forParameterKind::PositionalOnly
variant while required for all other variants.One change that's now required is that a
Callable
form using a gradual form for parameter types (...
) would have a defaultargs
andkwargs
name used for variadic and keyword-variadic parameter kind respectively. This is also the case for invalidCallable
type forms. I think this is fine as names are not relevant in this context but happy to make it optional even in variadic variants.Test Plan
No new tests; make sure existing tests are passing.