Skip to content

Move type-alias handling from handlers.llm into internals.unification - #767

Merged
jfeser merged 1 commit into
masterfrom
worktree-issue-766-alias-unification
Sep 2, 2026
Merged

Move type-alias handling from handlers.llm into internals.unification#767
jfeser merged 1 commit into
masterfrom
worktree-issue-766-alias-unification

Conversation

@eb8680

@eb8680 eb8680 commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Resolves #766

This pure refactoring PR moves some TypeAliasType-related type inference hotfixes added in #694 to the proper place in unification.py and adds regression tests that would have caught them.

…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>
@eb8680
eb8680 requested a review from jfeser September 2, 2026 03:57
@jfeser
jfeser merged commit 298e6ac into master Sep 2, 2026
35 checks passed
@jfeser
jfeser deleted the worktree-issue-766-alias-unification branch September 2, 2026 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Typing workarounds in handlers.llm.harness.serialization should be moved to internals.unification

2 participants