Skip to content

fix(py/plugins): move in-function import to top level in google-genai#4461

Merged
yesudeep merged 2 commits intomainfrom
yesudeep/fix/in-function-imports
Feb 6, 2026
Merged

fix(py/plugins): move in-function import to top level in google-genai#4461
yesudeep merged 2 commits intomainfrom
yesudeep/fix/in-function-imports

Conversation

@yesudeep
Copy link
Contributor

@yesudeep yesudeep commented Feb 6, 2026

Summary

Fixes in-function import warnings from bin/lint.

Changes

Real Fix: google-genai plugin

  • Moved BackgroundAction import from TYPE_CHECKING block to top level
  • The import was incorrectly placed in TYPE_CHECKING but is actually used at runtime for instantiation
  • Removed the duplicate in-function import that was working around this issue

Docstring Fixes

Converted docstring examples from :\: and triple-backtick markdown formats to Python doctest format (>>>) to avoid false positives in the in-function import lint check:

  • plugins/cloudflare-workers-ai/plugin.py
  • plugins/google-genai/rerankers/__init__.py
  • plugins/google-genai/evaluators/__init__.py
  • plugins/huggingface/plugin.py
  • plugins/mcp/server.py
  • plugins/mistral/plugin.py

Intentional Pattern Preserved

The microsoft-foundry/telemetry/tracing.py import warning is legitimate - it's a try/except import for optional dependencies (azure-monitor-opentelemetry-exporter), which is an acceptable pattern for optional dependencies.

Testing

  • bin/check_consistency now shows only the intentional optional dependency import
  • No functional changes - docstrings remain equivalent

BackgroundAction is used at runtime, so it needs to be a regular import,
not inside TYPE_CHECKING. Removes the duplicate in-function import.
@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 addresses a linting warning by refactoring an import statement for BackgroundAction. The import was previously conditionally loaded for type checking but was also required at runtime. By moving it to a top-level import and removing a redundant in-function import, the code is now cleaner, more efficient, and correctly handles the dependency, ensuring proper functionality and eliminating the warning.

Highlights

  • Import Refactoring: The BackgroundAction import has been moved from a TYPE_CHECKING block to a regular top-level import to ensure it's available at runtime for instantiation.
  • Redundant Import Removal: A duplicate in-function import of BackgroundAction within the _resolve_veo_model method has been removed, as it is now covered by the top-level import.
  • Lint Warning Resolution: This change resolves an in-function import warning reported by the bin/lint tool, improving code quality and adherence to best practices.

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

Changelog
  • py/plugins/google-genai/src/genkit/plugins/google_genai/google.py
    • Moved from genkit.blocks.background_model import BackgroundAction from within a if TYPE_CHECKING: block to a top-level import.
    • Removed TYPE_CHECKING from the typing module import as it is no longer used in this file.
    • Removed the in-function import from genkit.blocks.background_model import BackgroundAction from the _resolve_veo_model method.
Activity
  • No specific activity (comments, reviews, or progress updates) has been recorded for this pull request yet.
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 pull request correctly refactors the import of BackgroundAction in py/plugins/google-genai/src/genkit/plugins/google_genai/google.py. By moving the import to the top level, it resolves a linting warning and removes the need for a local, in-function import. The change is clean, improves code readability, and follows Python best practices. I have no further suggestions.

Converts markdown and :: code blocks in docstrings to Python doctest
format (>>>) to avoid false positives in in-function import checks.

The remaining warning for microsoft-foundry is a legitimate try/except
import for optional dependencies, which is an acceptable pattern.
@yesudeep yesudeep force-pushed the yesudeep/fix/in-function-imports branch from 1533882 to e597b8a Compare February 6, 2026 00:25
@yesudeep yesudeep enabled auto-merge (squash) February 6, 2026 00:25
@yesudeep yesudeep disabled auto-merge February 6, 2026 00:25
@yesudeep yesudeep enabled auto-merge (squash) February 6, 2026 00:26
@yesudeep yesudeep merged commit 7235768 into main Feb 6, 2026
17 checks passed
@yesudeep yesudeep deleted the yesudeep/fix/in-function-imports branch February 6, 2026 00:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants