[ty] normalize typevar bounds/constraints in cycles#21800
Merged
Conversation
Diagnostic diff on typing conformance testsNo changes detected when running ty on typing conformance tests ✅ |
|
dcreager
approved these changes
Dec 4, 2025
Member
dcreager
left a comment
There was a problem hiding this comment.
👍 to landing this separately from any follow-on work
AlexWaygood
approved these changes
Dec 4, 2025
carljm
commented
Dec 4, 2025
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
mtshiba
added a commit
to mtshiba/ruff
that referenced
this pull request
Dec 5, 2025
carljm
pushed a commit
that referenced
this pull request
Dec 5, 2025
dcreager
added a commit
that referenced
this pull request
Dec 5, 2025
* origin/main: (41 commits) [ty] Carry generic context through when converting class into `Callable` (#21798) [ty] Add more tests for renamings (#21810) [ty] Minor improvements to `assert_type` diagnostics (#21811) [ty] Add some attribute/method renaming test cases (#21809) Update mkdocs-material to 9.7.0 (Insiders now free) (#21797) Remove unused whitespaces in test cases (#21806) [ty] fix panic when instantiating a type variable with invalid constraints (#21663) [ty] fix build failure caused by conflicts between #21683 and #21800 (#21802) [ty] do nothing with `store_expression_type` if `inner_expression_inference_state` is `Get` (#21718) [ty] increase the limit on the number of elements in a non-recursively defined literal union (#21683) [ty] normalize typevar bounds/constraints in cycles (#21800) [ty] Update completion eval to include modules [ty] Add modules to auto-import [ty] Add support for module-only import requests [ty] Refactor auto-import symbol info [ty] Clarify the use of `SymbolKind` in auto-import [ty] Redact ranking of completions from e2e LSP tests [ty] Tweaks tests to use clearer language [ty] Update evaluation results [ty] Make auto-import ignore symbols in modules starting with a `_` ...
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.
Fixes astral-sh/ty#1587
Summary
Perform cycle normalization on typevar bounds and constraints (similar to how it was already done for typevar defaults) in order to ensure convergence in cyclic cases.
There might be another fix here that could avoid the cycle in many more cases, where we don't eagerly evaluate typevar bounds/constraints on explicit specialization, but just accept the given specialization and later evaluate to see whether we need to emit a diagnostic on it. But the current fix here is sufficient to solve the problem and matches the patterns we use to ensure cycle convergence elsewhere, so it seems good for now; left a TODO for the other idea.
This fix is sufficient to make us not panic, but not sufficient to get the semantics fully correct; see the TODOs in the tests. I have ideas for fixing that as well, but it seems worth at least getting this in to fix the panic.
Test Plan
Test that previously panicked now does not.