Skip to content

[ty] Avoid hangs on recursive tuple aliases in positive intersections - #29152

Closed
charliermarsh wants to merge 1 commit into
charlie/ty-3195-recursive-complementfrom
charlie/ty-shared-recursion-guards
Closed

charliermarsh wants to merge 1 commit into
charlie/ty-3195-recursive-complementfrom
charlie/ty-shared-recursion-guards

Conversation

@charliermarsh

@charliermarsh charliermarsh commented Oct 6, 2026 •

Copy link
Copy Markdown
Member

Summary

Builds on #29057. We now handle recursive tuple aliases specialized into positive intersections without hanging:

from collections.abc import Iterable
from typing import Any, assert_type
from ty_extensions import Intersection

type WithIterable[T] = Intersection[Iterable[Any], T]
type A = tuple[WithIterable[A], ...]

def f(x: A):
    reveal_type(x)  # tuple[WithIterable[A], ...]
    assert_type(x[0], WithIterable[A])

Previously, mapping the intersection unfolded A again after its mapping had completed. Each reconstruction could introduce another copy of the tuple, so even revealing x would not terminate.

We extend the existing alias-preservation mode to positive elements. The builder retains aliases to non-object nominal instances on the positive side and continues to apply its sign-specific rules for negated aliases. Aliases that expose object or set operations still expand, and ordinary intersection redundancy checks still run. The regressions cover both alias syntaxes, the returned element type, and an invalid assignment.

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

astral-sh-bot Bot commented Oct 6, 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 98.24%. The percentage of expected errors that received a diagnostic held steady at 98.24%. The number of fully passing files held steady at 134/146.

@astral-sh-bot

astral-sh-bot Bot commented Oct 6, 2026

Copy link
Copy Markdown

Memory usage report

Memory usage unchanged ✅

@astral-sh-bot

astral-sh-bot Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

ecosystem-analyzer results

No diagnostic changes detected ✅

Large timing changes:

Project Old Time New Time Change
more-itertools 0.13s 0.21s +60%

Full report with detailed diff (timing results)

@charliermarsh
charliermarsh force-pushed the charlie/ty-shared-recursion-guards branch from acc8ca7 to bca1de0 Compare October 6, 2026 20:53
@charliermarsh
charliermarsh changed the base branch from main to charlie/ty-3195-recursive-complement October 6, 2026 20:53
@charliermarsh
charliermarsh added this pull request to stack #29153 October 6, 2026 20:54
@charliermarsh
charliermarsh marked this pull request as ready for review October 6, 2026 20:54
@charliermarsh
charliermarsh requested a review from a team as a code owner October 6, 2026 20:54
@charliermarsh
charliermarsh removed this pull request from stack #29153 October 7, 2026 00:09

This branch was successfully deployed

1 active deployment
automations — bca1de0b Deployed Oct 6, 2026 by charliermarsh via security-review / security review #90866
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.

1 participant