feat[eve]: resolve PEP 695 type aliases in runtime annotation introspection - #2753
Closed
egparedes wants to merge 4 commits into
Closed
feat[eve]: resolve PEP 695 type aliases in runtime annotation introspection#2753egparedes wants to merge 4 commits into
egparedes wants to merge 4 commits into
Conversation
egparedes
marked this pull request as draft
August 6, 2026 06:31
Contributor
Author
|
Superseded by #2754. This PR covered only the The bugs found alongside it, which are independent of PEP 695, are in #2755. |
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.
Description
First PR in a stack adding PEP 695 (
type X = ...) type-alias support, now that the Python floor is 3.12 (#2326).GT4Py introspects annotations at runtime in several places, and none of them understand
TypeAliasType. On currentmaina type alias fails at class-definition time:This PR fixes that for
gt4py.eve. The follow-up PRs in the stack fix the user-facinggt4py.nextDSL path (where the same gap produces a bareValueErrorwith no source location) and add diagnostics for PEP 695 syntax written inside GT4Py functions.Note that PEP 695 generics (
class Model[T](DataModel)) already work unchanged and are not touched here — only the alias form was broken.What changed
eve.extended_typing: newis_type_alias()andeval_type_alias(). The latter follows alias chains, substitutes type parameters for parametrized aliases (MyAlias[int]), returns the identical object for non-aliases, and raisesTypeErroron recursive aliases (type A = A) via a depth cap.eve.type_validation: one branch in the annotation dispatch ofSimpleTypeValidatorFactory.__call__. Since that function already recurses into type arguments, nesting is handled for free.eve.datamodels: alias unwrapping in_make_type_converter(forCoerced[...]fields), and deferral of not-yet-resolvable aliases infield_type_validator_factory.docs/development/ADRs/eve/0001(neweve/ADR subsystem directory).Two things worth a reviewer's attention
xtyping.TypeAliasTypeis a trap. Becauseextended_typingstar-imports bothtypingandtyping_extensions, that name resolves to thetyping_extensionsclass — and a nativetype X = ...alias is not an instance of it:hasattr(x, "__value__")is the other trap: it isTrueforMyAlias[int]by attribute proxying to the origin, whileisinstance()isFalse. Hence a singleis_type_alias()predicate checking both classes, rather thanisinstancechecks spread over call sites. This is the main thing the ADR records.NameErroris a signal, not an error. Alias values are evaluated lazily, sotype LazyAlias = DefinedLaterraisesNameErroruntilDefinedLaterexists.type_validationdeliberately lets it propagate anddatamodelscatches it to install the existingForwardRefValidator, deferring validation to first instantiation — the same treatment string forward references already get. Accepted consequence: that field's errors surface later, and report the bare field name rather than the qualifiedModel.field, matching existing forward-reference behavior.Requirements
Validation
uv run pytest tests/eve_tests -q -n 4— 390 passeduv run pytest --doctest-modules -q src/gt4py/eve— 54 passeduv run mypy src/— no issues in 358 source filesuv run tach check— all modules validateduv run pre-commit run --files <changed>— all hooks pass