Skip to content

Conversation

@yesudeep
Copy link
Contributor

Fix all type checking issues identified by ty in test files:

  • Add MockerFixture import for pytest-mock's mocker fixture
  • Add assertions before calling functions expecting non-None values
    (e.g., assert resp.message is not None before text_from_message)
  • Change mock fixture return types to Any when tests create mock
    objects with mocked methods that break type contracts
  • Add cast() calls for nested dictionary accesses where types can't
    be inferred
  • Fix function signatures where return types didn't match returned
    values (e.g., return input.value or 0 for int return type)
  • Rename veneer/resource_test.py to veneer_resource_test.py to fix
    pytest import collision with ai/resource_test.py
  • Add noqa: ANN401 comments for intentional Any usage in fixtures
  • Use ActionKind.CUSTOM enum instead of string literal 'custom'
  • Fix BatchEvaluatorFn signature (async function returning list)
  • Fix Flask context provider to use RequestData[Request]
  • Fix HttpOptionsDict import in google-genai tests

Reduces ty errors from 414 to 0.

@yesudeep yesudeep changed the title fix(py/genkit): resolve all ty type errors in test files fix(py/genkit): resolve all ty type errors and ensure all functions have proper types Jan 26, 2026
Fix all type checking issues identified by ty in test files:

- Add MockerFixture import for pytest-mock's mocker fixture
- Add assertions before calling functions expecting non-None values
  (e.g., assert resp.message is not None before text_from_message)
- Change mock fixture return types to Any when tests create mock
  objects with mocked methods that break type contracts
- Add cast() calls for nested dictionary accesses where types can't
  be inferred
- Fix function signatures where return types didn't match returned
  values (e.g., return input.value or 0 for int return type)
- Rename veneer/resource_test.py to veneer_resource_test.py to fix
  pytest import collision with ai/resource_test.py
- Add noqa: ANN401 comments for intentional Any usage in fixtures
- Use ActionKind.CUSTOM enum instead of string literal 'custom'
- Fix BatchEvaluatorFn signature (async function returning list)
- Fix Flask context provider to use RequestData[Request]
- Fix HttpOptionsDict import in google-genai tests

Reduces ty errors from 414 to 0.
@yesudeep yesudeep force-pushed the yesudeep/fix/needless-trousers branch from ecaa453 to 925958f Compare January 26, 2026 06:20
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @yesudeep, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the type safety and maintainability of the Python Genkit codebase. It systematically addresses and resolves numerous type checking issues identified by ty, primarily by refining type annotations, replacing broad Any types with more specific ones, and ensuring consistent type contracts across various modules. The changes span core API definitions, internal utilities, and test files, aiming to improve code reliability and developer experience by providing clearer type information throughout the project.

Highlights

  • Enhanced Type Safety: Replaced numerous instances of the generic Any type with more specific types like object or TypedDict across various function signatures, parameters, and return types, particularly within core Genkit AI API methods and internal utility functions. This significantly improves type checking and code predictability.
  • Refined Type Hints in Core Modules: Updated type hints for configuration and metadata parameters in define_retriever, define_indexer, define_reranker, define_evaluator, define_batch_evaluator, define_model, define_embedder, define_prompt, and define_resource to use dict[str, object] or dict[str, SpanAttributeValue], providing clearer contracts for these functions.
  • Improved Flow and Action Wrappers: Modified flow wrappers (async_wrapper, sync_wrapper) to explicitly cast return types and handle single input arguments, removing previous type: ignore[arg-type] comments. Introduced noqa: ANN401 comments for intentional Any usage in fixtures and specific utility functions to satisfy stricter type checking rules.
  • Linting and Naming Convention Enforcement: Added ruff format to the bin/lint script for consistent code formatting and introduced a check to ensure Python test files adhere to the *_test.py naming convention, renaming py/packages/genkit/tests/genkit/ai/test_resource_integration.py to py/packages/genkit/tests/genkit/ai/resource_integration_test.py and similar files.
  • Protocol and Casting for Immutability: Introduced _LatencyTrackable and _ModelCopyable protocols in genkit.core.action._action.py to handle latency tracking and model copying for immutable Pydantic models, ensuring type correctness when modifying objects.
  • Generic ActionResponse: Made ActionResponse generic (ActionResponse[ResponseT]) to allow for more precise typing of the actual response data, enhancing type inference for action outputs.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Ignored Files
  • Ignored by pattern: .github/workflows/** (1)
    • .github/workflows/python.yml
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This is an excellent pull request that significantly improves the type safety of the Python codebase. The extensive changes to resolve ty type errors are thorough and well-executed. Replacing Any with more specific types like object, TypedDict, and generics, which significantly enhances code clarity and maintainability. The refactoring of some logic to be more robust and type-safe is also a welcome improvement. The consistency across the codebase is also commendable. Great job!

@yesudeep yesudeep enabled auto-merge (squash) January 26, 2026 06:39
@yesudeep
Copy link
Contributor Author

/gemini review

@yesudeep yesudeep disabled auto-merge January 26, 2026 06:40
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request does an excellent job of resolving a large number of type errors throughout the Python codebase. The changes significantly improve type safety and code robustness. I appreciate the thoroughness, especially the move from Any to more specific types like object or TypedDict, the addition of return types, and the refactoring of logic to be more type-safe. The introduction of asyncio.Queue for streaming in flows.py is a great fix for a potential bug.

I have found one important issue in Action.stream that could lead to incorrect behavior for consumers of streaming flows, and one suggestion to improve JSON serialization in flows.py.

Overall, this is a high-quality contribution that greatly improves the maintainability of the Python code.

- Replace MockInput classes with ResourceInput instances in tests
- Use resource() function instead of Action constructor for dynamic providers
- Change provider_fn return type from Action|None to object to avoid Pydantic schema generation errors
- Remove unused Action import

All 729 tests now pass.
@yesudeep yesudeep force-pushed the yesudeep/fix/needless-trousers branch from 9e5aec8 to 48a5496 Compare January 26, 2026 06:48
@yesudeep yesudeep enabled auto-merge (squash) January 26, 2026 06:48
@yesudeep yesudeep disabled auto-merge January 26, 2026 06:50
@yesudeep yesudeep enabled auto-merge (squash) January 26, 2026 06:53
@yesudeep yesudeep disabled auto-merge January 26, 2026 06:57
@yesudeep yesudeep enabled auto-merge (squash) January 26, 2026 06:57
@yesudeep yesudeep merged commit 0469d14 into main Jan 26, 2026
22 checks passed
@yesudeep yesudeep deleted the yesudeep/fix/needless-trousers branch January 26, 2026 07:01
MengqinShen pushed a commit that referenced this pull request Jan 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants