Skip to content

[ty] Preserve checks for recursive descriptor setter types - #29148

Merged
charliermarsh merged 1 commit into
mainfrom
charlie/codex-descriptor-dependencies
Oct 22, 2026
Merged

charliermarsh merged 1 commit into
mainfrom
charlie/codex-descriptor-dependencies

Conversation

@charliermarsh

@charliermarsh charliermarsh commented Oct 6, 2026 •

Copy link
Copy Markdown
Member

Summary

This PR fixes a stack overflow when checking a protocol's writable member whose descriptor setter accepts a recursive type. For example, checking the assignment below previously aborted the process instead of reporting an invalid assignment:

from __future__ import annotations

from typing import Protocol

class Recursive[T](Protocol):
    next: Recursive[list[T]]

class Descriptor:
    def __init__(self, getter: object) -> None: ...
    def __get__(self, instance: object, owner: type | None = None) -> int:
        return 1

    def __set__[U](self, instance: object, value: Recursive[int]) -> None: ...

class HasValue(Protocol):
    @Descriptor
    def value(self) -> int: ...

def update(obj: HasValue) -> None:
    obj.value = 1  # Invalid: the setter requires Recursive[int].

The setter's unused U triggers a search to determine whether the accepted value type depends on that type parameter. The existing search follows next through Recursive[int], Recursive[list[int]], Recursive[list[list[int]]], and so on. Its recursion guard remembers exact types, so these changing specializations never repeat and the search overflows the stack. Removing U avoids the search and the crash.

We replace that general type search with a dependency check that recognizes repeated definitions and inspects the arguments of recursive references without repeatedly expanding their bodies. Here, it establishes that the setter accepts Recursive[int] independently of U, so we can report the invalid assignment normally. The same fix covers recursive TypedDicts and type aliases, while retaining checks for assignments and protocol compatibility.

@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
@charliermarsh
charliermarsh added this pull request to stack #29150 October 6, 2026 20:05
@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 ✅

Flaky changes detected. This PR summary excludes flaky changes; see the HTML report for details.

Full report with detailed diff (timing results)

@charliermarsh
charliermarsh marked this pull request as ready for review October 6, 2026 20:57
@charliermarsh
charliermarsh requested a review from a team as a code owner October 6, 2026 20:57
@charliermarsh
charliermarsh removed this pull request from stack #29150 October 6, 2026 23:50
@charliermarsh
charliermarsh added this pull request to stack #29156 October 6, 2026 23:50
@charliermarsh
charliermarsh force-pushed the charlie/codex-descriptor-dependencies branch from edcaf05 to e55268b Compare October 7, 2026 02:00
@charliermarsh
charliermarsh force-pushed the charlie/codex-descriptor-dependencies branch from e55268b to 1c3ad9e Compare October 7, 2026 13:54
@charliermarsh
charliermarsh force-pushed the charlie/codex-descriptor-dependencies branch from 1c3ad9e to b2b979c Compare October 14, 2026 00:13
@codspeed

codspeed Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 184 untouched benchmarks
⏩ 70 skipped benchmarks1


Comparing charlie/codex-descriptor-dependencies (9de8914) with main (2c63593)

Open in CodSpeed

Footnotes

  1. 70 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@charliermarsh
charliermarsh force-pushed the charlie/codex-descriptor-dependencies branch from b2b979c to d724bf2 Compare October 15, 2026 17:58
Base automatically changed from charlie/codex-tuple-promotion to main October 15, 2026 18:22
@charliermarsh
charliermarsh force-pushed the charlie/codex-descriptor-dependencies branch from d724bf2 to d325eb3 Compare October 15, 2026 18:22
@charliermarsh
charliermarsh force-pushed the charlie/codex-descriptor-dependencies branch from d325eb3 to 8b6e7f7 Compare October 15, 2026 19:57
Inspect dependencies on the setter signature explicitly, including recursive aliases, protocols, and TypedDicts. Recursive specializations that are independent of the setter parameters retain their writable-member checks.

Co-authored-by: Ibraheem Ahmed <ibraheem@ibraheem.ca>
@charliermarsh
charliermarsh force-pushed the charlie/codex-descriptor-dependencies branch from 8b6e7f7 to 9de8914 Compare October 20, 2026 20:27
@charliermarsh
charliermarsh merged commit b0f9526 into main Oct 22, 2026
75 of 76 checks passed
@charliermarsh
charliermarsh deleted the charlie/codex-descriptor-dependencies branch October 22, 2026 11:33

This branch was previously deployed

1 inactive deployment
automations — 9de89146 Deployed Oct 20, 2026 by charliermarsh via security-review / security review #92378
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