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

Skip to content

[ty] Avoid TypedDict schema cycle for Self fields#25094

Merged
charliermarsh merged 1 commit into
mainfrom
typed-dict-self-cycle
May 11, 2026
Merged

[ty] Avoid TypedDict schema cycle for Self fields#25094
charliermarsh merged 1 commit into
mainfrom
typed-dict-self-cycle

Conversation

@charliermarsh

Copy link
Copy Markdown
Member

Summary

Self in a class-based TypedDict field can cause field annotation inference to recursively inspect the same TypedDict schema while it is still being collected. This PR makes TypedDictType::items cycle-safe for class-based schemas by using an empty schema as the cycle fallback, matching the lower-level field collector's recovery behavior.

For example, this no longer panics:

from typing_extensions import Self, TypedDict

class A(TypedDict):
    pass

class B(TypedDict):
    foo: A | Self

_: B = {}

Closes astral-sh/ty#3437.

@astral-sh-bot astral-sh-bot Bot added the ty Multi-file analysis & type inference label May 11, 2026
@charliermarsh charliermarsh added the bug Something isn't working label May 11, 2026
@astral-sh-bot

astral-sh-bot Bot commented May 11, 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 89.36%. The percentage of expected errors that received a diagnostic held steady at 85.49%. The number of fully passing files held steady at 88/134.

@astral-sh-bot

astral-sh-bot Bot commented May 11, 2026

Copy link
Copy Markdown

Memory usage report

Memory usage unchanged ✅

@astral-sh-bot

astral-sh-bot Bot commented May 11, 2026

Copy link
Copy Markdown

ecosystem-analyzer results

No diagnostic changes detected ✅

Full report with detailed diff (timing results)

@charliermarsh charliermarsh marked this pull request as ready for review May 11, 2026 03:12
@charliermarsh charliermarsh merged commit c5d4645 into main May 11, 2026
58 checks passed
@charliermarsh charliermarsh deleted the typed-dict-self-cycle branch May 11, 2026 12:31
thejchap pushed a commit to thejchap/ruff that referenced this pull request May 23, 2026
## Summary

`Self` in a class-based `TypedDict` field can cause field annotation
inference to recursively inspect the same `TypedDict` schema while it is
still being collected. This PR makes `TypedDictType::items` cycle-safe
for class-based schemas by using an empty schema as the cycle fallback,
matching the lower-level field collector's recovery behavior.

For example, this no longer panics:

```py
from typing_extensions import Self, TypedDict

class A(TypedDict):
    pass

class B(TypedDict):
    foo: A | Self

_: B = {}
```

Closes astral-sh/ty#3437.
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.

panic: dependency graph cycle when querying class_based_items with typing.Self

2 participants