Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[ty] Avoid cross-TypeVar leakage in generic inference#26099

Merged
charliermarsh merged 1 commit into
mainfrom
charlie/filter-generic-solver-artifacts
Jun 17, 2026
Merged

[ty] Avoid cross-TypeVar leakage in generic inference#26099
charliermarsh merged 1 commit into
mainfrom
charlie/filter-generic-solver-artifacts

Conversation

@charliermarsh

@charliermarsh charliermarsh commented Jun 17, 2026

Copy link
Copy Markdown
Member

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)) against Mapping[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 both dict parameters to widen to int | float. This fails on main:

from collections.abc import Iterable, Mapping

def build(
    keys: Iterable[float],
    values: Iterable[int],
) -> Mapping[float, int]:
    return dict(zip(keys, values))

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 self remapping and similar inference.

@charliermarsh charliermarsh added the ty Multi-file analysis & type inference label Jun 17, 2026
@astral-sh-bot

astral-sh-bot Bot commented Jun 17, 2026

Copy link
Copy Markdown

Typing conformance results

No changes detected ✅

Current numbers
The 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.

@astral-sh-bot

astral-sh-bot Bot commented Jun 17, 2026

Copy link
Copy Markdown

Memory usage report

Memory usage unchanged ✅

@astral-sh-bot

astral-sh-bot Bot commented Jun 17, 2026

Copy link
Copy Markdown

ecosystem-analyzer results

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]]`

Full report with detailed diff (timing results)

@charliermarsh charliermarsh marked this pull request as ready for review June 17, 2026 13:54
@charliermarsh charliermarsh requested a review from a team as a code owner June 17, 2026 13:54
@charliermarsh charliermarsh requested a review from dcreager June 17, 2026 13:54
@astral-sh-bot astral-sh-bot Bot requested a review from dhruvmanila June 17, 2026 13:54
@charliermarsh charliermarsh added the bug Something isn't working label Jun 17, 2026

@dcreager dcreager left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable!

@charliermarsh charliermarsh merged commit 95ddc34 into main Jun 17, 2026
60 checks passed
@charliermarsh charliermarsh deleted the charlie/filter-generic-solver-artifacts branch June 17, 2026 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants