Skip to content

[ty] Restrict range implications from gradual equivalence - #29577

Merged
carljm merged 2 commits into
mainfrom
cjm/fix-gradual-equivalence-sequents
Oct 22, 2026
Merged

carljm merged 2 commits into
mainfrom
cjm/fix-gradual-equivalence-sequents

Conversation

@carljm

@carljm carljm commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Fix false invalid-argument-type errors when inferring constrained type variables from callbacks that return an invariant generic with a gradual type argument. A callback returning Box[Any] can satisfy Callable[[], T | Box[T]] when T is constrained to str or bytes.

The solver treated equivalence to a gradual type as exact substitution, allowing a valid union alternative to imply an incompatible bound. Require a static equivalence bound before deriving either lower- or upper-bound implications, including when gradual types are nested inside a bound.

Prerequisite to avoid regressions in #29236.

@carljm carljm added bug An issue describing something that isn't working, or a PR that fixes a bug ty The ty type checker labels Oct 21, 2026
@astral-sh-bot

This comment was marked as outdated.

@astral-sh-bot

This comment was marked as off-topic.

@astral-sh-bot

This comment was marked as outdated.

@carljm
carljm requested a review from dcreager October 21, 2026 04:17
@carljm
carljm marked this pull request as ready for review October 21, 2026 04:17
@carljm
carljm requested a review from a team as a code owner October 21, 2026 04:17
Two-way assignability to a gradual type does not fix a type variable to that type. Require a static equivalence bound before deriving either a lower or upper bound, preserving valid alternatives while rejecting incompatible conjunctions.
@carljm
carljm force-pushed the cjm/fix-gradual-equivalence-sequents branch from ff680f8 to 90a1525 Compare October 21, 2026 23:28
@carljm
carljm added this pull request to stack #29605 October 21, 2026 23:36
@carljm

carljm commented Oct 21, 2026

Copy link
Copy Markdown
Contributor Author

Analysis results for 90a1525cc2

All three analysis workflows completed successfully. These results compare 90a1525cc2a5cf62d678ce200dffe1d68a88e38b against base 3bf4988cf062dc76895ff2f8421acf766172392b, and are posted manually while astral-bot is unavailable. CI analyzed merge commit e1f96ad4ebf26c22e3520cb7c302b212a597be1e, whose tree matches the PR head.

Memory usage

No measured increase in total Salsa database memory across the four benchmark projects:

Project Base PR Change
flake8 38.01 MiB 38.01 MiB unchanged
trio 92.73 MiB 92.73 MiB −244 B
sphinx 172.56 MiB 172.56 MiB −936 B
prefect 479.35 MiB 479.34 MiB −10.19 KiB

The small net reductions primarily come from for_constraint_pair_inner. Totals retain the report's rounding; units are binary.

Memory workflow · Detailed comparison

Typing conformance

No diagnostic changes. Precision and recall both remain 98.24%, with 134/146 files fully passing on both sides. The suite is python/typing at d06c5dd6, targeting Python 3.12.

Conformance workflow · Comparison report

Ecosystem

No diagnostic changes across 163 projects. No added or removed projects, failed projects, or flaky exit-status changes were reported.

Independently regenerated the diagnostic comparison, statistics, and timing reports from all four CI shards using the workflow's pinned analyzer and dependencies. They match the CI reports; the check for new abnormal exits also passed.

Ecosystem workflow · Full diagnostic and timing reports

The measurements and suite executions above were performed in CI. Artifact checksums, run provenance, and memory/conformance report agreement with the job logs were verified manually. Those two workflows retain rendered comparisons rather than raw measurement/diagnostic JSON, so their computations were not independently repeated locally.

@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.

👍

@carljm
carljm merged commit 48dcdd0 into main Oct 22, 2026
76 checks passed
@carljm
carljm deleted the cjm/fix-gradual-equivalence-sequents branch October 22, 2026 14:45

This branch was previously deployed

1 inactive deployment
automations — 90a1525c Deployed Oct 21, 2026 by carljm via security-review / security review #92614
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug An issue describing something that isn't working, or a PR that fixes a bug ty The ty type checker

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants