Skip to content

Conversation

@zzstoatzz
Copy link
Collaborator

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

  • ✅ Updated all Union[X, Y] to use the modern X | Y syntax
  • ✅ Replaced all Optional[T] with T | None
  • ✅ Fixed forward reference type annotations to work with pipe operator
  • ✅ Kept Union imports only where required (TypedDict fields with forward references)

Testing

  • ✅ All tests passing with the modern syntax
  • ✅ Pre-commit hooks passing (ruff, ruff-format, etc.)

Files Modified

  • src/marvin/_internal/deprecation.py - Updated type hints
  • src/marvin/agents/actor.py - Updated type hints
  • src/marvin/engine/orchestrator.py - Updated type hints
  • src/marvin/memory/providers/postgres.py - Updated type hints
  • src/marvin/tasks/task.py - Updated type hints
  • src/marvin/thread.py - Updated type hints
  • src/marvin/utilities/jsonschema.py - Updated type hints (kept Union for TypedDict)
  • src/marvin/utilities/types.py - Updated type hints

Related Issues

Closes #1222 - Prepare for Pydantic AI v1.0 release

Benefits

With Python 3.10+ as the minimum version, we can now use:

  • match/case statements for cleaner pattern matching
  • X | Y union types without imports
  • @dataclass(kw_only=True) for better dataclass ergonomics
  • Parenthesized context managers
  • Better error messages

Next Steps

Future PRs can leverage match/case statements to refactor complex conditional logic where it improves readability.

- 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+
Copilot AI review requested due to automatic review settings August 29, 2025 17:46
@github-actions github-actions bot added the documentation Improvements or additions to documentation label Aug 29, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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] to X | Y and Optional[T] to T | None across the codebase
  • Removes unnecessary Optional imports where no longer needed
  • Maintains Union imports 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.

zzstoatzz and others added 3 commits August 29, 2025 12:48
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.
@zzstoatzz zzstoatzz merged commit 8dc1e91 into main Aug 29, 2025
4 checks passed
@zzstoatzz zzstoatzz deleted the python-3.10-modernization branch August 29, 2025 18:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prepare for Pydantic AI v1.0 release

2 participants