Modernize codebase for Python 3.10+#1223
Merged
Merged
Conversation
- Update type hints to use X | Y instead of Union[X, Y] - Replace Optional[T] with T | None throughout codebase - Fix forward reference type annotations to work with pipe operator - Keep Union for TypedDict fields with forward references (required) - All tests passing with modern syntax This prepares for Pydantic AI v1.0 which will require Python 3.10+
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR modernizes the Marvin codebase to use Python 3.10+ type hint syntax, replacing Union and Optional with the new pipe operator syntax in preparation for Pydantic AI v1.0.
- Updates all
Union[X, Y]toX | YandOptional[T]toT | Noneacross the codebase - Removes unnecessary
Optionalimports where no longer needed - Maintains
Unionimports only where required for TypedDict fields with forward references
Reviewed Changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/marvin/_internal/deprecation.py | Updated function parameter type hints to use pipe syntax |
| src/marvin/agents/actor.py | Updated ContextVar and return type annotations |
| src/marvin/engine/orchestrator.py | Updated return type annotation for get_current method |
| src/marvin/memory/providers/postgres.py | Updated class attribute type hints |
| src/marvin/tasks/task.py | Updated ContextVar type annotation |
| src/marvin/thread.py | Updated ContextVar and return type annotations |
| src/marvin/utilities/jsonschema.py | Updated type hints while preserving Union for TypedDict |
| src/marvin/utilities/types.py | Updated docstring type annotations |
| docs/ | Updated documentation to reflect modernized type hints |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
The sessionmaker itself can be None, not the sessions it creates. Changed from async_sessionmaker[AsyncSession | None] to async_sessionmaker[AsyncSession] | None Co-authored-by: Copilot <175728472+copilot-pull-request-reviewer[bot]@users.noreply.github.com>
The test expects dataclass fields to use typing.Union which has __origin__ attribute. The new pipe syntax (field_type | None) creates types.UnionType which doesn't have __origin__. Keep using Union[field_type, None] for dynamically generated dataclass fields to maintain backward compatibility with existing tests and user code that may depend on the __origin__ attribute.
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
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.