Repository navigation
[ty] Guard recursive constructor bindings by receiver - #27958
Merged
Merged
Conversation
Track active constructor receiver types while resolving call bindings and recover with a gradual signature when a receiver repeats. Preserve descriptor-sensitive and finite generic constructor chains, along with downstream argument checks. Add regression coverage for decorator-induced, mutual, and generic constructor cycles and the finite cases that must not be truncated. Fixes astral-sh/ty#4347.
Typing conformance resultsNo changes detected ✅Current numbersThe percentage of diagnostics emitted that were expected errors held steady at 97.68%. The percentage of expected errors that received a diagnostic held steady at 93.44%. The number of fully passing files held steady at 109/136. |
Memory usage reportMemory usage unchanged ✅ |
|
charliermarsh
approved these changes
Aug 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes astral-sh/ty#4347.
Constructor signature expansion can revisit the same receiver through class-valued
__new__,__init__, or metaclass__call__, recursively expanding bindings until ty overflows the stack. A generic decorator that replaces__new__withtype[C]is one way to trigger this.Track active constructor receivers during binding expansion and return a gradual signature when an exact receiver repeats, letting the enclosing constructor supply the instance return type. Comparing full receiver types preserves finite generic chains and descriptor overloads that distinguish
Cfromtype[C].Test plan
Extend the constructor mdtests to cover:
__init__, metaclass__call__, and callable instances.__init__argument validation and known non-instance return types from__new__or metaclass__call__.The full
ty_python_semantictest suite, Clippy, and applicable repository hooks pass.