[ty] Support Unpack[TypedDict] for precise **kwargs typing (PEP 692)#22771
[ty] Support Unpack[TypedDict] for precise **kwargs typing (PEP 692)#22771bxff wants to merge 1 commit intoastral-sh:mainfrom
Unpack[TypedDict] for precise **kwargs typing (PEP 692)#22771Conversation
Typing conformance results improved 🎉The percentage of diagnostics emitted that were expected errors increased from 79.65% to 79.90%. The percentage of expected errors that received a diagnostic increased from 70.95% to 71.80%. Summary
True positives addedDetails
False positives removedDetails
False positives addedDetails
Optional Diagnostics AddedDetails
|
|
Hey @bxff -- really appreciate the PRs you've been sending recently! I love how quickly you're knocking down issues, but we still have a bit of a PR backlog from the beta release and the Christmas break. Would you mind holding off on opening any more until we've had a chance to finish reviewing the ones you've already opened? It'll probably make it a better experience for you, because your PRs are less likely to sit unreviewed for extended periods of time (which can lead to annoying merge conflicts for you) :-) |
c6efb3e to
f4cb61a
Compare
|
|
| Lint rule | Added | Removed | Changed |
|---|---|---|---|
invalid-argument-type |
47 | 6 | 5 |
unused-type-ignore-comment |
1 | 28 | 0 |
unknown-argument |
21 | 1 | 0 |
no-matching-overload |
8 | 0 | 0 |
invalid-assignment |
0 | 5 | 2 |
invalid-parameter-default |
0 | 0 | 7 |
not-subscriptable |
0 | 7 | 0 |
invalid-return-type |
0 | 2 | 3 |
possibly-missing-attribute |
0 | 4 | 0 |
invalid-method-override |
3 | 0 | 0 |
| Total | 80 | 53 | 17 |
|
(I'll review this PR as this was something that I planned on doing anyways :)) |
f6042e0 to
db10fa0
Compare
## Summary Closes astral-sh/ty#1746 Partially addresses astral-sh/ty#154 This PR implements PEP 692 support for using Unpack[TypedDict] to provide more precise type annotations for **kwargs parameters. Implementation details: - Add KnownInstanceType::UnpackedTypedDict(TypedDictType) variant - Parse Unpack[TypedDict] in type expressions, emit errors for invalid usage - Type kwargs as the TypedDict itself inside function bodies - Validate keyword arguments against TypedDict fields at call sites - Report unknown-argument for kwargs not in the TypedDict - Report missing-argument for required TypedDict fields not provided - Check argument types against specific TypedDict field types - Handle **typed_dict_var passthrough with field-by-field type checking Not yet implemented (out of scope, separate PEP 646 features): - Unpack[TypeVarTuple] - returns todo_type! - Unpack[tuple[...]] - returns todo_type! ## Test Plan New mdtest file annotations/unpack_kwargs.md with comprehensive coverage.
db10fa0 to
858348b
Compare
Summary
Closes astral-sh/ty#1746 Partially addresses astral-sh/ty#154 ("Support for
Unpack" checkbox)This PR implements PEP 692 support for using
Unpack[TypedDict]to provide more precise type annotations for**kwargsparameters. Previously,**kwargs: strmeant all keyword arguments are strings. With this change, you can specify exactly which keyword arguments are expected:Implementation details:
KnownInstanceType::UnpackedTypedDict(TypedDictType)variantUnpack[TypedDict]in type expressions, emit errors for invalid usagekwargsas the TypedDict itself inside function bodiesunknown-argumentfor kwargs not in the TypedDictmissing-argumentfor required TypedDict fields not provided**typed_dict_varpassthrough with field-by-field type checkingNot yet implemented (out of scope, separate PEP 646 features):
Unpack[TypeVarTuple]- returnstodo_type!Unpack[tuple[...]]- returnstodo_type!Test Plan
New mdtest file
annotations/unpack_kwargs.mdwith comprehensive coverage:reveal_typeverification****