Skip to content

Conversation

@justinli34
Copy link

Link to Issue or Description of Change

Problem:
The ContextFilterPlugin.custom_filter parameter has an incorrect type signature. It's declared as Callable[[List[Event]], List[Event]] but is actually called with list[types.Content] from llm_request.contents in the before_model_callback method. This type mismatch could lead to runtime errors and prevents proper type checking.

Solution:
Changed the type signature of custom_filter to Callable[[list[types.Content]], list[types.Content]] to match its actual usage. This ensures type safety and allows static type checkers to properly validate code that uses this plugin.

Testing Plan

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.

Existing unit tests continue to pass. The change is a type annotation fix that doesn't alter runtime behavior, so existing test coverage validates the fix.

Pytest output:

3674 passed, 1 skipped, 2192 warnings in 101.27s (0:01:41)

Manual End-to-End (E2E) Tests:
Type checking validation:

  • Ran mypy on the modified file to confirm no type errors
  • Verified that custom filter implementations now receive correct type hints in IDEs

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • I have manually tested my changes end-to-end.
  • Any dependent changes have been merged and published in downstream modules.

Additional context

This is a type annotation fix that improves type safety without changing runtime behavior. Users who have implemented custom filters may need to update their type hints if they were following the incorrect signature, though the runtime behavior remains unchanged.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @justinli34, 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 addresses a critical type inconsistency within the ContextFilterPlugin by correcting the signature of its custom_filter method. This ensures that the type hints accurately reflect the data types being processed, thereby enhancing type safety and enabling more robust static analysis without introducing any changes to the plugin's operational behavior at runtime.

Highlights

  • Type Signature Correction: The type signature for ContextFilterPlugin.custom_filter has been updated from Callable[[List[Event]], List[Event]] to Callable[[list[types.Content]], list[types.Content]] to accurately reflect its actual usage.
  • Improved Type Safety: This change resolves a type mismatch, ensuring proper type checking and enabling static type checkers to validate code using this plugin correctly.
  • No Runtime Behavior Change: The fix is purely a type annotation update and does not alter the runtime behavior of the application.

🧠 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.

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.

@adk-bot adk-bot added the core [Component] This issue is related to the core interface and implementation label Dec 31, 2025
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 correctly fixes a type mismatch in the ContextFilterPlugin.custom_filter signature, changing it from Callable[[List[Event]], List[Event]] to Callable[[List[types.Content]], List[types.Content]]. This aligns the type hint with its actual usage in before_model_callback, improving type safety. The change is well-described and necessary. I have one minor suggestion for consistency.

num_invocations_to_keep: Optional[int] = None,
custom_filter: Optional[Callable[[List[Event]], List[Event]]] = None,
custom_filter: Optional[
Callable[[List[types.Content]], List[types.Content]]
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

For consistency with other parts of the codebase (e.g., llm_request.py which uses list[types.Content]) and to align with the PR description, it would be better to use the built-in list type hint instead of typing.List. This is the modern approach for Python 3.9+ and seems to be adopted in other files. Using list here would also allow for the removal of the from typing import List import, which would become unused.

Suggested change
Callable[[List[types.Content]], List[types.Content]]
Callable[[list[types.Content]], list[types.Content]]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core [Component] This issue is related to the core interface and implementation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants