[ty] Avoid cross-TypeVar leakage in generic inference#26099
Merged
Conversation
Typing conformance resultsNo changes detected ✅Current numbersThe percentage of diagnostics emitted that were expected errors held steady at 94.37%. The percentage of expected errors that received a diagnostic held steady at 89.00%. The number of fully passing files held steady at 94/134. |
Memory usage reportMemory usage unchanged ✅ |
|
| Lint rule | Added | Removed | Changed |
|---|---|---|---|
invalid-assignment |
1 | 5 | 0 |
| Total | 1 | 5 | 0 |
Flaky changes detected. This PR summary excludes flaky changes; see the HTML report for details.
Raw diff:
Expression (https://github.com/cognitedata/Expression)
+ tests/test_compose.py:21:16 error[invalid-assignment] Object of type `(_A@compose, /) -> _A@compose` is not assignable to `(int, /) -> int`
django-modern-rest (https://github.com/wemake-services/django-modern-rest)
- dmr/security/jwt/blocklist/models.py:30:23 error[invalid-assignment] Object of type `CharField[int | str | Combinable, int | str | Combinable]` is not assignable to `CharField[int | str | Combinable, str]`
- dmr/security/jwt/blocklist/models.py:34:34 error[invalid-assignment] Object of type `DateTimeField[str | datetime | Combinable, str | datetime | Combinable]` is not assignable to `DateTimeField[str | datetime | Combinable, datetime]`
- dmr/security/jwt/blocklist/models.py:35:34 error[invalid-assignment] Object of type `DateTimeField[str | datetime | Combinable, str | datetime | Combinable]` is not assignable to `DateTimeField[str | datetime | Combinable, datetime]`
- dmr/security/jwt/blocklist/models.py:38:34 error[invalid-assignment] Object of type `DateTimeField[str | datetime | Combinable, str | datetime | Combinable]` is not assignable to `DateTimeField[str | datetime | Combinable, datetime]`
meson (https://github.com/mesonbuild/meson)
- mesonbuild/compilers/compilers.py:104:44 error[invalid-assignment] Object of type `dict[str, str]` is not assignable to `Mapping[str, Literal["c", "cpp", "cuda", "fortran", "d", ... omitted 11 literals]]`
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
Generic return-type context can introduce relationships between type variables while solving a call. We need those relationships during constraint solving, but we previously reused them as concrete preferred types during argument inference.
For example, inferring
dict(zip(keys, values))againstMapping[float, int]can derive a key solution containing the value TypeVar and a value solution containing the key TypeVar. Treating those intermediate relationships as final solutions causes bothdictparameters to widen toint | float. This fails onmain:This projects inferable TypeVar artifacts within each source binding context before using solutions as preferred types. Relationships across separate generic contexts remain intact, preserving constructor
selfremapping and similar inference.