fix(fns): resolve return annotations with from __future__ import annotations#1326
Closed
CrepuscularIRIS wants to merge 1 commit into
Closed
fix(fns): resolve return annotations with from __future__ import annotations#1326CrepuscularIRIS wants to merge 1 commit into
from __future__ import annotations#1326CrepuscularIRIS wants to merge 1 commit into
Conversation
…otations` When PEP 563 (`from __future__ import annotations`) is active, all type annotations become strings. `PythonFunction.from_function()` was reading `sig.return_annotation` directly, which returned a string like "Recipe" instead of the actual class. This caused `@marvin.fn` decorated functions to return strings instead of typed objects. Use `typing.get_type_hints()` to resolve stringified annotations back to their actual types, with a fallback to the original behavior when resolution fails (e.g., unresolvable forward references). Fixes PrefectHQ#950
CrepuscularIRIS
added a commit
to CrepuscularIRIS/Beatless
that referenced
this pull request
Apr 14, 2026
- auto-pr.sh: Real submission pipeline (discover → fix → review → PR) - github-pr-state.json: 0.5h interval, lock file prevents concurrency - github-hunt: DISABLED in heartbeat-driver - First real PR submitted: PrefectHQ/marvin#1326 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Author
|
Closing this PR — no maintainer activity in 2+ weeks. Happy to reopen or resubmit if you'd like to revisit. Thanks for the project! |
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
Fixes #950
When
from __future__ import annotations(PEP 563) is active in a module, all type annotations become strings at runtime.PythonFunction.from_function()readssig.return_annotationdirectly, which returns a string like"Recipe"instead of the actualRecipeclass. This causes@marvin.fndecorated functions to produce string outputs instead of typed Pydantic model instances.Root Cause
inspect.signature(func).return_annotationreturns the raw annotation value. Under PEP 563, annotations are stored as strings and not evaluated until explicitly resolved. The fix atsrc/marvin/utilities/types.py:372was using this raw value without resolution.Changes
src/marvin/utilities/types.py: Add_resolve_return_annotation()helper that usestyping.get_type_hints()to resolve stringified annotations, with a fallback tosig.return_annotationwhen resolution fails (handles unresolvable forward refs, built-in functions, etc.)tests/basic/utilities/test_types.py: Add 4 tests covering: future annotations resolution, normal annotations, no annotation, and unresolvable forward ref fallbacktests/basic/utilities/_future_annotations_helper.py: Test helper module withfrom __future__ import annotationsactiveTesting
# Verify: uv run pytest tests/basic/utilities/test_types.py -vNotes
Minimal fix — only changes the annotation resolution path. No unrelated changes. The approach follows the same
typing.get_type_hints()strategy suggested in #1258. The exception handler is narrowed toKeyError | NameError | AttributeError | TypeErrorto avoid masking unexpected errors.