Modernize codebase for Python 3.10+ #1223
Merged
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
This PR modernizes the Marvin codebase to use Python 3.10+ features in preparation for Pydantic AI v1.0, which will require Python 3.10+.
Changes
Type Hint Modernization
Union[X, Y]to use the modernX | YsyntaxOptional[T]withT | NoneUnionimports only where required (TypedDict fields with forward references)Testing
Files Modified
src/marvin/_internal/deprecation.py- Updated type hintssrc/marvin/agents/actor.py- Updated type hintssrc/marvin/engine/orchestrator.py- Updated type hintssrc/marvin/memory/providers/postgres.py- Updated type hintssrc/marvin/tasks/task.py- Updated type hintssrc/marvin/thread.py- Updated type hintssrc/marvin/utilities/jsonschema.py- Updated type hints (kept Union for TypedDict)src/marvin/utilities/types.py- Updated type hintsRelated Issues
Closes #1222 - Prepare for Pydantic AI v1.0 release
Benefits
With Python 3.10+ as the minimum version, we can now use:
match/casestatements for cleaner pattern matchingX | Yunion types without imports@dataclass(kw_only=True)for better dataclass ergonomicsNext Steps
Future PRs can leverage
match/casestatements to refactor complex conditional logic where it improves readability.