[ty] Create fresh copies of generic callable typevars#24949
Draft
dcreager wants to merge 26 commits into
Draft
Conversation
Typing conformance resultsNo changes detected ✅Current numbersThe percentage of diagnostics emitted that were expected errors held steady at 89.34%. The percentage of expected errors that received a diagnostic held steady at 85.30%. The number of fully passing files held steady at 87/134. |
Memory usage reportSummary
Significant changesClick to expand detailed breakdownprefect
sphinx
trio
flake8
|
|
| Lint rule | Added | Removed | Changed |
|---|---|---|---|
invalid-argument-type |
4 | 0 | 0 |
invalid-assignment |
0 | 1 | 0 |
| Total | 4 | 1 | 0 |
Raw diff:
Expression (https://github.com/cognitedata/Expression)
+ expression/collections/maptree.py:176:36 error[invalid-argument-type] Argument to function `try_find` is incorrect: Expected `Option[MapTreeLeaf[Key@try_find, Never]]`, found `Option[MapTreeLeaf[Never, Never]]`
setuptools (https://github.com/pypa/setuptools)
- setuptools/glob.py:76:34 error[invalid-assignment] Object of type `Iterator[str]` is not assignable to `Iterable[AnyStr@_iglob]`
+ setuptools/glob.py:76:41 error[invalid-argument-type] Argument to function `_iglob` is incorrect: Argument type `AnyStr@_iglob & ~AlwaysFalsy` does not satisfy constraints (`str`, `bytes`) of type variable `AnyStr`
xarray (https://github.com/pydata/xarray)
+ xarray/backends/api.py:1363:42 error[invalid-argument-type] Argument to function `_remove_path` is incorrect: Expected `NestedSequence[_FLike@_remove_path]`, found `(_FLike@_remove_path & Top[list[Unknown]]) | (NestedSequence[_FLike@_remove_path] & Top[list[Unknown]])`
+ xarray/core/utils.py:356:35 error[invalid-argument-type] Argument to function `flat_items` is incorrect: Expected `Mapping[str, dict[str, Divergent] | Unknown]`, found `dict[str, Divergent] | (T@flat_items & Top[dict[Unknown, Unknown]])`
Merging this PR will degrade performance by 5.31%
Performance Changes
Comparing Footnotes
|
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.
A generic callable binds new typevars. If that callable is used more than once in a particular expression, we should create separate (aka "fresh") copies of those typevars, so that the inferred types for each do not conflict with each other.
This comes up in two situations:
We might invoke a generic function recursively from inside of its body. In that case, the call site introduces fresh inferable copies of the function's typevars, which should not conflict with the existing non-inferable copies from the function signature.
We might pass the same generic callable more than once to some other call. In this case, each occurrence should have distinct copies of its typevars, that do not need to unify with each other. This can occur whenever we compare a generic callable signature for assignability with some other signature.
This PR updates these two places (call binding and signature assignability checking) to introduce fresh copies of the callable's typevars when needed. There are still some mdtests that are marked as TODOs, because they depend on combining constraint sets across multiple arguments (#24540).