Move type-alias handling from handlers.llm into internals.unification - #767
Merged
Conversation
…ion` (#766) #694 landed handling for PEP 695 aliases as registrations against `canonicalize`, `TypeEvaluator.evaluate` and `nested_type` from inside `handlers.llm.harness.serialization`, each marked `TODO move upstream`. Nothing about them is LLM-specific, and living where they did made core behavior depend on whether the LLM module had been imported: without that import, `canonicalize` and the evaluator raise `RecursionError` on a self-referential alias, a subscripted generic alias is left unexpanded, and `nested_type` reports `TypeAliasType` rather than what the alias names. The registrations move verbatim, keeping the evaluator's in-progress alias set on the instance, with one change: the guard now keys on the alias rather than on the subscripted form, so an alias that reapplies itself at a different argument (`type T[X] = list[T[list[X]]]`) terminates rather than expanding forever. No existing case is affected -- a recursive alias reached through itself repeats the same subscription. `unify` is untouched, but stops diverging on a recursive alias as a consequence: it canonicalizes its arguments first, and now gets an opaque constant back instead of an unbounded expansion. The alias coverage this never had goes in `tests/test_internals_unification.py`. It has to be stated there rather than in the LLM suite: `tests/conftest.py` imports the harness, so every test in `tests/` already ran with these registrations installed, which is how the gap survived #694. Run against unmodified master with the LLM module unimported, 14 of the new tests fail. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
jfeser
approved these changes
Sep 2, 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.
Resolves #766
This pure refactoring PR moves some
TypeAliasType-related type inference hotfixes added in #694 to the proper place inunification.pyand adds regression tests that would have caught them.