Repository navigation
Conversation
Module-level type aliases like
Source = Annotated[dagger.Directory, dagger.DefaultPath(".")]
were silently mishandled. The resolver fell through ``_resolve_name``
and warn-assumed ``Source`` was an opaque object type, while
``extract_annotated_metadata`` saw only ``Name("Source")`` and dropped
``DefaultPath`` along with the rest of the ``Annotated`` payload.
Collect type-shaped top-level assignments into a per-file alias map
and expand the alias before metadata extraction and resolution at every
annotation entry point (field, class assignment, function parameter,
return type). The surface annotation string still keeps the alias name
so the user-facing representation is unchanged. Chained aliases are
followed; a visited-set guards against cycles.
Signed-off-by: Yves Brissaud <[email protected]>
suprjinx
pushed a commit
to G-Research-Forks/dagger
that referenced
this pull request
May 5, 2026
… AST analyzer
Module-level type aliases like
Source = Annotated[dagger.Directory, dagger.DefaultPath(".")]
were silently mishandled. The resolver fell through ``_resolve_name``
and warn-assumed ``Source`` was an opaque object type, while
``extract_annotated_metadata`` saw only ``Name("Source")`` and dropped
``DefaultPath`` along with the rest of the ``Annotated`` payload.
Collect type-shaped top-level assignments into a per-file alias map
and expand the alias before metadata extraction and resolution at every
annotation entry point (field, class assignment, function parameter,
return type). The surface annotation string still keeps the alias name
so the user-facing representation is unchanged. Chained aliases are
followed; a visited-set guards against cycles.
Signed-off-by: Yves Brissaud <[email protected]>
Signed-off-by: Geoff Wilson <[email protected]>
This was referenced May 5, 2026
Member
Author
|
Included in #13095 that covers more python AST issues |
eunomie
added a commit
to eunomie/dagger
that referenced
this pull request
May 6, 2026
PEP 695 (Python 3.12+) introduced a dedicated ``ast.TypeAlias`` node for the ``type Source = ...`` statement. ``_collect_module_constants`` only iterated ``ast.Assign`` and ``ast.AnnAssign``, so PEP 695 aliases never made it into ``_module_type_aliases`` and were silently treated as opaque object types — the same failure mode the legacy alias path fixed in dagger#13093. Add an explicit ``ast.TypeAlias`` branch that registers the alias under the same alias map. ``_expand_alias`` then walks PEP 695 aliases through chains and the existing cycle protection, so all the existing alias machinery applies. Closes dagger#11803 follow-up gap C1. Signed-off-by: Yves Brissaud <[email protected]>
eunomie
added a commit
to eunomie/dagger
that referenced
this pull request
May 6, 2026
PR dagger#13093 made module-level type aliases work, but its alias map was keyed per-file: ``Source = Annotated[dagger.Directory, …]`` defined in ``types.py`` and imported via ``from .types import Source`` in ``main.py`` was not expanded — the analyzer fell back to treating ``Source`` as an opaque object type and the ``DefaultPath`` metadata was dropped. Track which names each file brought in via relative imports (``_collect_relative_imports``) and follow those edges in ``_expand_alias`` so cross-file aliases resolve. Cycle protection now keys on ``(file, name)`` rather than just ``name`` so the same alias name can appear in multiple files without false-positive cycle stops. The relative-import-target resolver maps the AST level + module path to a concrete parsed file (``.py`` or ``__init__.py``) and is best-effort — if the target isn't in the parsed set (third-party package, dynamic ``__path__``), the entry is omitted and existing warn-and-stub behavior takes over. Closes dagger#11803 follow-up gap C2. Signed-off-by: Yves Brissaud <[email protected]>
eunomie
added a commit
to eunomie/dagger
that referenced
this pull request
May 6, 2026
PEP 695 (Python 3.12+) introduced a dedicated ``ast.TypeAlias`` node for the ``type Source = ...`` statement. ``_collect_module_constants`` only iterated ``ast.Assign`` and ``ast.AnnAssign``, so PEP 695 aliases never made it into ``_module_type_aliases`` and were silently treated as opaque object types — the same failure mode the legacy alias path fixed in dagger#13093. Add an explicit ``ast.TypeAlias`` branch that registers the alias under the same alias map; ``_expand_alias`` then walks PEP 695 aliases through chains and the existing cycle protection. The alias map was also keyed per-file: ``Source = Annotated[…]`` defined in ``types.py`` and imported via ``from .types import Source`` in ``main.py`` was not expanded — the analyzer fell back to treating ``Source`` as an opaque object type and the metadata was dropped. Track which names each file brought in via relative imports (``_collect_relative_imports``) and follow those edges in ``_expand_alias`` so cross-file aliases resolve. Cycle protection now keys on ``(file, name)`` rather than just ``name`` so the same alias name can appear in multiple files without false-positive cycle stops. The relative-import-target resolver maps the AST level + module path to a concrete parsed file (``.py`` or ``__init__.py``) and is best-effort — if the target isn't in the parsed set (third-party package, dynamic ``__path__``), the entry is omitted and existing warn-and-stub behaviour takes over. ``ast.TypeAlias`` itself only exists on Python 3.12+; accessing it on 3.10 / 3.11 raises ``AttributeError`` and crashed every test against the analyzer at module-constants collection. Resolve the attribute once at import time via ``getattr(ast, "TypeAlias", None)`` and short-circuit the ``isinstance`` check on that. PEP 695 source can't be parsed by the older ``ast`` module anyway, so the branch is genuinely a no-op there. Test fixtures that pass PEP 695 source strings to ``analyze_source_string`` (``test_ast_pep695_*``) are gated with a ``@requires_py312`` marker so they don't ``SyntaxError`` at parse time on 3.10 / 3.11. ``dagger call python-sdk python-{310, 311,312,313,314} unit`` all green. Closes dagger#11803 follow-up gaps C1, C2. Signed-off-by: Yves Brissaud <[email protected]>
suprjinx
pushed a commit
to G-Research-Forks/dagger
that referenced
this pull request
May 12, 2026
… AST analyzer
Module-level type aliases like
Source = Annotated[dagger.Directory, dagger.DefaultPath(".")]
were silently mishandled. The resolver fell through ``_resolve_name``
and warn-assumed ``Source`` was an opaque object type, while
``extract_annotated_metadata`` saw only ``Name("Source")`` and dropped
``DefaultPath`` along with the rest of the ``Annotated`` payload.
Collect type-shaped top-level assignments into a per-file alias map
and expand the alias before metadata extraction and resolution at every
annotation entry point (field, class assignment, function parameter,
return type). The surface annotation string still keeps the alias name
so the user-facing representation is unchanged. Chained aliases are
followed; a visited-set guards against cycles.
Signed-off-by: Yves Brissaud <[email protected]>
Signed-off-by: Geoff Wilson <[email protected]>
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
The AST analyzer used by
dagger developfor the Python SDK silently mishandled module-level type aliases such as:Two things went wrong:
Sourcewas never registered in the analyzer's namespace, so_resolve_namefell through to its catch-all path and warn-assumedSourcewas an opaque object type. The resultingTypeDefcarriedkind=object name=Sourceinstead ofname=Directory.Annotatedmetadata:extract_annotated_metadataoperated on the rawast.Name("Source")and saw noAnnotated[...]wrapper, soDefaultPath(".")(and anyDoc,Name,Ignore,Deprecated) were dropped on the floor.Fix
Collect type-shaped top-level assignments into a per-file alias map and expand the alias before metadata extraction and resolution at every annotation entry point (field, class assignment, function parameter, and function/constructor return type).
Subscript,Attribute,Name,T | None) are recorded — plain string/number constants stay out of the type-resolution path.B = A; A = dagger.Directory) are followed; a visited-set guards against cycles."Source"), only resolution and metadata extraction see the expansion.Test plan
sdk/python/tests/mod/test_ast_analyzer.pycovering:Annotatedalias as parameter (asserts bothDirectoryresolution anddefault_path="."),Annotatedalias as field, plain alias (Src = dagger.Directory), optional alias (MaybeDir = dagger.Directory | None), chained alias, and a self-referential cycle (must not recurse).