Skip to content

Conversation

keith
Copy link
Member

@keith keith commented Sep 12, 2025

This optionally fetches PyInfo from bazel_features during the
transition.

This optionally fetches PyInfo from bazel_features during the
transition.
Copy link

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

Summary of Changes

Hello @keith, 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 introduces a critical compatibility layer to gracefully handle the upcoming changes in Bazel 9.x regarding the PyInfo provider. By adding a new dependency and implementing a conditional fallback mechanism, the system can adapt to whether the legacy PyInfo is present or if a new PyInfo from bazel_features is available. This ensures that the mypy rules continue to function correctly and resolve Python-related information across different Bazel versions during the transition period.

Highlights

  • Dependency Update: Added a new bazel_dep for bazel_features at version 1.21.0 in the MODULE.bazel file.
  • PyInfo Compatibility Layer: Introduced a mechanism to handle the potential removal or change of PyInfo in Bazel 9.x by conditionally fetching it from bazel_features.globals.PyInfo or falling back to RulesPythonPyInfo.
  • Code Adaptation: Updated mypy/private/mypy.bzl to utilize the new _LegacyPyInfo alias when checking for and accessing PyInfo attributes within the _imports and _mypy_impl functions, ensuring forward compatibility.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

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 issue 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

@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 updates the Bazel configuration to handle the upcoming removal of the built-in PyInfo provider in Bazel 9.x by using bazel_features for a backward-compatible transition. The changes correctly introduce bazel_features as a dependency and use it to conditionally access the legacy PyInfo. My review includes suggestions to improve the clarity and maintainability of the compatibility logic by making the distinction between the legacy and modern PyInfo providers more explicit, which will prevent redundant checks and make the code easier to understand.

load("@rules_python//python:py_info.bzl", RulesPythonPyInfo = "PyInfo")
load(":py_type_library.bzl", "PyTypeLibraryInfo")

_LegacyPyInfo = bazel_features.globals.PyInfo or RulesPythonPyInfo

Choose a reason for hiding this comment

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

medium

This definition of _LegacyPyInfo can be misleading. On newer Bazel versions where bazel_features.globals.PyInfo is None, this variable will hold RulesPythonPyInfo, which is the modern provider. This makes the name inaccurate and leads to redundant elif checks in _imports and _mypy_impl.

A clearer approach is to have this variable only hold the legacy provider. This makes the name accurate and simplifies the logic at the call sites.

_LegacyPyInfo = bazel_features.globals.PyInfo

Copy link
Member Author

Choose a reason for hiding this comment

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

i considered this but didn't really feel worth complicating the callsites when this will be the low traffic path

Comment on lines +37 to +38
elif _LegacyPyInfo in target:
return target[_LegacyPyInfo].imports.to_list()

Choose a reason for hiding this comment

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

medium

With _LegacyPyInfo representing only the legacy provider (as suggested for line 16), this check should ensure the provider is not None before using it. This change avoids a redundant check on newer Bazel versions where the built-in PyInfo is removed.

    elif _LegacyPyInfo and _LegacyPyInfo in target:
        return target[_LegacyPyInfo].imports.to_list()

return []

if RulesPythonPyInfo not in target and PyInfo not in target:
if RulesPythonPyInfo not in target and _LegacyPyInfo not in target:

Choose a reason for hiding this comment

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

medium

To align with the suggested refactoring on line 16, this check for the legacy provider should also verify that it exists (is not None) before checking for its presence in the target. This improves clarity and robustness during the transition across Bazel versions.

    if RulesPythonPyInfo not in target and not (_LegacyPyInfo and _LegacyPyInfo in target):

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant