Skip to content

Conversation

@yesudeep
Copy link
Contributor

@yesudeep yesudeep commented Feb 1, 2026

Summary

Clean up PLC0415 (import at top-level) violations in the core Genkit framework.

Changes

File Change
packages/genkit/src/genkit/ai/_aio.py Import cleanup
packages/genkit/src/genkit/ai/_registry.py Import cleanup
packages/genkit/src/genkit/aio/loop.py Added noqa for optional uvloop import with comment
packages/genkit/src/genkit/blocks/background_model.py Import cleanup
packages/genkit/src/genkit/blocks/session/session.py Import cleanup
packages/genkit/src/genkit/core/_plugins.py Fixed import with noqa and comment
packages/genkit/src/genkit/core/plugin.py Added noqa with circular import comments
packages/genkit/src/genkit/core/trace/default_exporter.py Moved imports to top
packages/genkit/src/genkit/web/manager/_adapters.py Added noqa with lazy loading comments
packages/genkit/tests/ Moved test imports to module level

Related

Test Plan

  • All Ruff checks pass
  • bin/lint passes
  • CI will validate tests

@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 Python codebase hygiene within the Genkit framework by systematically addressing PLC0415 violations, which pertain to in-function imports. The changes involve relocating numerous imports to the module level for better adherence to Python best practices and improved static analysis. Additionally, specific instances of necessary lazy imports, such as those for optional server adapters or certain core components, have been explicitly marked with noqa comments to maintain functionality while acknowledging the linter rule. This effort contributes to a cleaner, more maintainable, and compliant Python environment for Genkit.

Highlights

  • Enforced Top-Level Imports: Many in-function Python imports across the core Genkit framework have been moved to the top of their respective files. This addresses PLC0415 violations and improves code readability and static analysis.
  • Strategic noqa Annotations: For specific cases where in-function imports are necessary (e.g., optional dependencies like uvloop, uvicorn, granian, or to avoid circular dependencies), noqa: PLC0415 comments have been added to suppress linter warnings, explicitly marking these as intentional lazy imports.
  • Test File Import Cleanup: In-function imports within various test files have also been refactored to be top-level, ensuring consistent import practices across the entire codebase.

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

@yesudeep yesudeep force-pushed the yesudeep/fix/plc0415-core-framework branch from 67f2ba0 to c3db14b Compare February 1, 2026 00:36
@github-actions github-actions bot added the config label Feb 1, 2026
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 a good job of cleaning up in-function imports to adhere to PLC0415 (import at top-level). Most of the changes correctly move imports to the top of the file or add noqa directives for valid exceptions like optional dependencies. However, I've found one critical issue in py/packages/genkit/src/genkit/core/_plugins.py where removing an import breaks the plugin discovery mechanism. Please see the detailed comment for the fix.

@yesudeep yesudeep force-pushed the yesudeep/fix/plc0415-core-framework branch 3 times, most recently from 48f0fdb to 6b5d7f1 Compare February 1, 2026 00:50
@yesudeep yesudeep force-pushed the yesudeep/fix/plc0415-core-framework branch from 6b5d7f1 to 0d47a28 Compare February 1, 2026 01:17
@yesudeep
Copy link
Contributor Author

yesudeep commented Feb 1, 2026

/gemini review

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 provides a solid cleanup of in-function imports, moving them to the top level to address PLC0415 violations. The changes are applied consistently across the core framework and test files. The cases where imports remain within functions for lazy loading or to prevent circular dependencies are correctly handled with noqa directives and clear comments. This refactoring improves code quality and readability without introducing any issues. Great work!

@yesudeep yesudeep enabled auto-merge (squash) February 1, 2026 02:03
@yesudeep yesudeep requested a review from pavelgj February 2, 2026 01:43
yesudeep added a commit that referenced this pull request Feb 2, 2026
The core framework has some intentional in-function imports for lazy
loading and circular import avoidance. These are being cleaned up in
PR #4400. Until that PR is merged, exclude packages/genkit from the
in-function imports check to avoid CI failures.

The check now only scans plugins/*/src/ for in-function imports.
Move imports to module top-level or add noqa comments for intentional
deferred imports (uvloop optional loading, lazy server adapter imports,
circular import avoidance).

Changes:
- packages/genkit/src: Move exports to top, add noqa for lazy imports
- packages/genkit/tests: Move test imports to module level

Related to #4398
@yesudeep yesudeep force-pushed the yesudeep/fix/plc0415-core-framework branch from 0d47a28 to 13ff01f Compare February 2, 2026 07:32
@yesudeep yesudeep merged commit a69b008 into main Feb 2, 2026
23 checks passed
@yesudeep yesudeep deleted the yesudeep/fix/plc0415-core-framework branch February 2, 2026 18:02
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.

3 participants