Repository navigation
Conversation
Move the existing inheritance subtest out of TestDocs into a dedicated TestInheritance suite so future inheritance-related tests have a clear home. Pure refactor - no behavior change. Renames "inheritance" to the more specific "inherited create constructor" since it tests inheritance of the create() classmethod constructor. Signed-off-by: Yves Brissaud <[email protected]>
Closes dagger#13089 PR dagger#11803 (v0.20.7) replaced the runtime introspection-based analyzer with a static AST parser. The previous code relied on inspect.getmembers(), which walks the Python MRO and naturally discovers @function-decorated methods inherited from base classes. The AST parser only walks node.body, missing every inherited method. Constructor inheritance was already handled via _find_inherited_constructor; mirror that pattern with _find_inherited_functions so @function methods follow the same MRO traversal. Walks node.bases recursively, skips names already defined on the child (overrides win), and uses a visited set for cycle safety. Inherited functions are parsed with the child's class_name so Self annotations resolve to the child type, matching runtime behavior. _find_class_def is split so callers can also recover the parent's file path; inherited functions are then parsed against that path so location metadata points at the actual definition site. Tests: - AST analyzer unit tests cover the issue repro, child override, and multi-level (grandparent) inheritance. - New TestInheritance/inherited functions integration test mirrors the issue's "Steps to reproduce" through inspectModuleObjects. Signed-off-by: Yves Brissaud <[email protected]>
eunomie
force-pushed
the
sdk-python-inherited-functions
branch
from
May 5, 2026 12:11
a1444b5 to
86d3c12
Compare
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
PR dagger#13090 fixed inherited ``@function`` methods but left ``dagger.field()`` declarations on base classes invisible — ``_extract_class_members`` only iterated the child's ``node.body``. A ``class Child(Base):`` where ``Base`` declared ``name: str = dagger.field(default="x")`` would have an empty ``fields=[]`` and an auto-derived constructor with no ``name`` parameter, diverging from how ``dataclasses.fields()`` walks the MRO at runtime. Mirror the ``_find_inherited_functions`` pattern with ``_find_inherited_fields`` that walks ``node.bases`` recursively (visited set, override wins, parsed against the child's class name so ``Self`` resolves correctly). The walker emits both the FieldMetadata and the matching constructor ParameterMetadata so the auto-derived ``__init__`` picks up the inherited fields too. Closes dagger#11803 follow-up gap F1. Signed-off-by: Yves Brissaud <[email protected]>
eunomie
added a commit
to eunomie/dagger
that referenced
this pull request
May 6, 2026
PR dagger#13090 fixed inherited ``@function`` methods but left ``dagger.field()`` declarations on base classes invisible — ``_extract_class_members`` only iterated the child's ``node.body``. A ``class Child(Base):`` where ``Base`` declared ``name: str = dagger.field(default="x")`` would have an empty ``fields=[]`` and an auto-derived constructor with no ``name`` parameter, diverging from how ``dataclasses.fields()`` walks the MRO at runtime. Mirror the ``_find_inherited_functions`` pattern with ``_find_inherited_fields`` that walks ``node.bases`` recursively (visited set, override wins, parsed against the child's class name so ``Self`` resolves correctly). The walker emits both the FieldMetadata and the matching constructor ParameterMetadata so the auto-derived ``__init__`` picks up the inherited fields too. The walker is gated on ``_is_dataclass_like`` — at runtime, dagger fields flow through ``dataclasses.fields(cls)``, which only inherits from base classes that are themselves dataclasses (i.e. ``@dagger.object_type`` / ``@dagger.interface``, which apply ``dataclass`` internally, or an explicit ``@dataclass``). An undecorated base's annotations are *not* promoted to fields on the child. Without the gate, the analyzer claimed otherwise and produced phantom fields the engine wouldn't actually expose; the new differential test suite caught the divergence and a new ``test_ast_undecorated_base_does_not_inherit_fields`` locks in the correct behaviour. Closes dagger#11803 follow-up gap F1. Signed-off-by: Yves Brissaud <[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
@functionmethods stopped showing up indagger functions/dagger call --helpwhen the Python SDK switched from runtime introspection to a static AST analyzer in v0.20.7 (feat(sdk/python): AST based analysis to introspect #11803). The new analyzer iterated only over a class's ownnode.bodyand never walked base classes for@functionmethods, whileinspect.getmembers()previously discovered them via Python's MRO._find_inherited_constructorpattern: a new_find_inherited_functionsrecursively walksnode.bases, skips names already defined on the child (overrides win), and uses avisitedset for cycle safety. Inherited functions are parsed with the child's class name soSelfresolves to the child type — matching runtime behavior._find_class_defis split so the parent's file path can also be recovered, giving inherited functions accurate location metadata.inheritancesubtest out ofTestDocsinto a dedicatedTestInheritancesuite (first patch, no behavior change), then adds the new integration test next to it (second patch).Test plan
pytest sdk/python/tests/mod/— 178 passed (existing 175 + 3 new analyzer tests covering: issue repro, child override of an inherited@function, grandparent inheritance).ruff checkclean.go vet ./core/integration/...clean.go test ./core/integration/ -run 'TestPython/TestInheritance'— runs the two integration subtests (inherited create constructor,inherited functions) end-to-end against the dev engine.