[ty] Infer generic class pattern specializations - #26420
Closed
charliermarsh wants to merge 12 commits into
Closed
Conversation
Typing conformance resultsNo changes detected ✅Current numbersThe percentage of diagnostics emitted that were expected errors held steady at 94.47%. The percentage of expected errors that received a diagnostic held steady at 89.19%. The number of fully passing files held steady at 95/134. |
Memory usage reportMemory usage unchanged ✅ |
|
| Lint rule | Added | Removed | Changed |
|---|---|---|---|
invalid-return-type |
21 | 0 | 2 |
invalid-argument-type |
12 | 0 | 0 |
invalid-yield |
2 | 0 | 0 |
| Total | 35 | 0 | 2 |
Raw diff (37 changes)
Expression (https://github.com/cognitedata/Expression)
+ expression/collections/maptree.py:503:24 error[invalid-return-type] Return type does not match returned value: expected `tuple[Key@MkIterator, Value@MkIterator]`, found `tuple[SupportsLessThan, object]`
+ expression/core/option.py:73:24 error[invalid-return-type] Return type does not match returned value: expected `_TSourceOut@Option | _TSource@default_value`, found `object`
+ expression/core/option.py:85:24 error[invalid-return-type] Return type does not match returned value: expected `_TSourceOut@Option | _TSource@default_with`, found `object`
+ expression/core/option.py:97:36 error[invalid-argument-type] Argument is incorrect: Expected `_TSourceOut@Option`, found `object`
+ expression/core/option.py:109:36 error[invalid-argument-type] Argument is incorrect: Expected `_TSourceOut@Option`, found `object`
+ expression/core/option.py:142:31 error[invalid-argument-type] Argument is incorrect: Expected `_TSourceOut@Option`, found `object`
+ expression/core/option.py:173:61 error[invalid-argument-type] Argument is incorrect: Expected `_TSourceOut@Option`, found `object`
+ expression/core/option.py:182:24 error[invalid-return-type] Return type does not match returned value: expected `list[_TSourceOut@Option]`, found `list[object]`
+ expression/core/option.py:193:24 error[invalid-return-type] Return type does not match returned value: expected `Seq[_TSourceOut@Option]`, found `Seq[object]`
+ expression/core/option.py:232:24 error[invalid-return-type] Return type does not match returned value: expected `_TSourceOut@Option | None`, found `object`
+ expression/core/option.py:242:24 error[invalid-return-type] Return type does not match returned value: expected `Result[_TSourceOut@Option, _TError@to_result]`, found `Result[object, _TError@to_result]`
+ expression/core/option.py:252:24 error[invalid-return-type] Return type does not match returned value: expected `Result[_TSourceOut@Option, _TError@to_result_with]`, found `Result[object, _TError@to_result_with]`
+ expression/core/option.py:264:24 error[invalid-return-type] Return type does not match returned value: expected `_TSourceOut@Option | None`, found `object`
+ expression/core/option.py:276:24 error[invalid-return-type] Return type does not match returned value: expected `_TSourceOut@Option`, found `object`
+ expression/core/option.py:286:31 error[invalid-yield] Yield type `object` does not match annotated yield type `_TSourceOut@Option`
+ expression/core/option.py:304:24 error[invalid-return-type] Return type does not match returned value: expected `_TSourceOut@Option`, found `object`
+ expression/core/result.py:81:24 error[invalid-return-type] Return type does not match returned value: expected `_TSourceOut@Result | _TSource@default_value`, found `object`
+ expression/core/result.py:93:24 error[invalid-return-type] Return type does not match returned value: expected `_TSource@default_with | _TSourceOut@Result`, found `object`
+ expression/core/result.py:95:31 error[invalid-argument-type] Argument is incorrect: Expected `_TErrorOut@Result`, found `object`
+ expression/core/result.py:105:63 error[invalid-argument-type] Argument is incorrect: Expected `_TSourceOut@Result`, found `object`
+ expression/core/result.py:107:24 error[invalid-return-type] Return type does not match returned value: expected `Result[_TResult@map, _TErrorOut@Result]`, found `Result[_TResult@map, object]`
+ expression/core/result.py:121:56 error[invalid-argument-type] Argument is incorrect: Expected `_TSourceOut@Result`, found `object`
+ expression/core/result.py:123:24 error[invalid-return-type] Return type does not match returned value: expected `Result[_TResult@map2, _TErrorOut@Result]`, found `Result[_TResult@map2, object]`
+ expression/core/result.py:133:24 error[invalid-return-type] Return type does not match returned value: expected `Result[_TSourceOut@Result, _TResult@map_error]`, found `Result[object, _TResult@map_error]`
+ expression/core/result.py:135:67 error[invalid-argument-type] Argument is incorrect: Expected `_TErrorOut@Result`, found `object`
+ expression/core/result.py:145:31 error[invalid-argument-type] Argument is incorrect: Expected `_TSourceOut@Result`, found `object`
+ expression/core/result.py:147:24 error[invalid-return-type] Return type does not match returned value: expected `Result[_TResult@bind, _TErrorOut@Result]`, found `Result[_TResult@bind, object]`
+ expression/core/result.py:166:58 error[invalid-argument-type] Argument is incorrect: Expected `_TSourceOut@Result`, found `object`
+ expression/core/result.py:184:58 error[invalid-argument-type] Argument is incorrect: Expected `_TSourceOut@Result`, found `object`
+ expression/core/result.py:187:38 error[invalid-argument-type] Argument is incorrect: Expected `_TSourceOut@Result`, found `object`
+ expression/core/result.py:198:24 error[invalid-return-type] Return type does not match returned value: expected `dict[str, _TSourceOut@Result | _TErrorOut@Result | Literal["ok", "error"]]`, found `dict[str, object]`
+ expression/core/result.py:203:24 error[invalid-return-type] Return type does not match returned value: expected `dict[str, _TSourceOut@Result | _TErrorOut@Result | Literal["ok", "error"]]`, found `dict[str, object]`
+ expression/core/result.py:236:24 error[invalid-return-type] Return type does not match returned value: expected `Option[_TSourceOut@Result]`, found `Option[object]`
+ expression/core/result.py:255:31 error[invalid-yield] Yield type `object` does not match annotated yield type `_TSourceOut@Result`
+ expression/core/result.py:263:24 error[invalid-return-type] Return type does not match returned value: expected `_TSourceOut@Result`, found `object`
- expression/core/result.py:209:24 error[invalid-return-type] Return type does not match returned value: expected `Result[_TErrorOut@Result, _TSourceOut@Result]`, found `Result[_TSourceOut@Result, _TSourceOut@Result]`
+ expression/core/result.py:209:24 error[invalid-return-type] Return type does not match returned value: expected `Result[_TErrorOut@Result, _TSourceOut@Result]`, found `Result[Unknown, object]`
- expression/core/result.py:211:24 error[invalid-return-type] Return type does not match returned value: expected `Result[_TErrorOut@Result, _TSourceOut@Result]`, found `Result[_TSourceOut@Result, _TSourceOut@Result]`
+ expression/core/result.py:211:24 error[invalid-return-type] Return type does not match returned value: expected `Result[_TErrorOut@Result, _TSourceOut@Result]`, found `Result[object, Unknown]`
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.
Summary
Follow-up to #26411.
When a generic class pattern is a subclass of the subject's class, the subject specialization constrains which pattern-class specializations can match. We previously discarded that relationship and treated members declared by the subclass as
Unknown:This PR uses the constraint solver to find every specialization of the pattern subclass whose corresponding base is compatible with the subject. It projects the captured member over the complete set of solutions instead of selecting a single preferred type argument. Separate constraint paths remain correlated, and lower and upper bounds are preserved through covariant, contravariant, and invariant member positions.
The same projection handles transformed bases, partially constrained subclasses, TypeVar bounds and constraints, and unconstrained parameters. Runtime matching continues to ignore type-parameter defaults, while generic base patterns and unrelated classes retain the existing conservative behavior.
The focused regression assertions fail on
mainwithUnknown; the fullty_python_semanticsuite, workspace Clippy, and repository hooks pass with the new inference.