Skip to content

Conversation

@parthea
Copy link
Contributor

@parthea parthea commented Jan 30, 2026

Towards #15104

This is needed to unblock #15457 .

See follow up issue googleapis/proto-plus-python#558 for the prerelease presubmit failure.

See the following mypy failure for google-cloud-monitoring

2026-01-16T21:21:02.1088102Z nox > Running session mypy-3.14
2026-01-16T21:21:02.1093302Z nox > Creating virtual environment (virtualenv) using python3.14 in .nox/mypy-3-14
2026-01-16T21:21:02.3445193Z nox > python -m pip install 'mypy<1.16.0' types-requests types-protobuf
2026-01-16T21:21:05.5617360Z nox > python -m pip install .
2026-01-16T21:21:10.8264379Z nox > mypy -p google
2026-01-16T21:21:26.4063416Z .nox/mypy-3-14/lib/python3.14/site-packages/google/cloud/monitoring_v3/__init__.py:232: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs  [annotation-unchecked]
2026-01-16T21:21:26.4393843Z .nox/mypy-3-14/lib/python3.14/site-packages/google/cloud/monitoring_v3/_dataframe.py:20: error: Library stubs not installed for "pandas"  [import-untyped]
2026-01-16T21:21:26.4396224Z .nox/mypy-3-14/lib/python3.14/site-packages/google/cloud/monitoring_v3/_dataframe.py:20: note: Hint: "python3 -m pip install pandas-stubs"
2026-01-16T21:21:26.4398337Z .nox/mypy-3-14/lib/python3.14/site-packages/google/cloud/monitoring_v3/_dataframe.py:20: note: (or run "mypy --install-types" to install all missing stub packages)
2026-01-16T21:21:26.4400993Z .nox/mypy-3-14/lib/python3.14/site-packages/google/cloud/monitoring_v3/_dataframe.py:20: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports

See the following mypy failure for google-cloud-org-policy

2026-01-16T21:25:54.1998139Z nox > Running session mypy-3.14
2026-01-16T21:25:54.2002997Z nox > Creating virtual environment (virtualenv) using python3.14 in .nox/mypy-3-14
2026-01-16T21:25:54.4531153Z nox > python -m pip install 'mypy<1.16.0' types-requests types-protobuf
2026-01-16T21:25:57.9686970Z nox > python -m pip install .
2026-01-16T21:26:03.3150701Z nox > mypy -p google
2026-01-16T21:26:13.7960116Z .nox/mypy-3-14/lib/python3.14/site-packages/google/cloud/orgpolicy/v1/__init__.py:26: error: Need type annotation for "names" (hint: "names: list[<type>] = ...")  [var-annotated]

See the following mypy failure for google-cloud-speech

.nox/mypy-3-14/lib/python3.14/site-packages/google/cloud/speech_v1p1beta1/__init__.py:131: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs  [annotation-unchecked]
.nox/mypy-3-14/lib/python3.14/site-packages/google/cloud/speech_v1p1beta1/__init__.py:172: error: Name "SpeechClient" already defined (possibly by an import)  [no-redef]
.nox/mypy-3-14/lib/python3.14/site-packages/google/cloud/speech_v1p1beta1/__init__.py:172: error: Definition of "streaming_recognize" in base class "SpeechHelpers" is incompatible with definition in base class "SpeechClient"  [misc]

See the following failure for google-cloud-vision

2026-01-16T21:48:11.3461545Z nox > mypy -p google
2026-01-16T21:48:23.0397649Z google/cloud/vision_helpers/__init__.py:18: error: Skipping analyzing "proto": module is installed, but missing library stubs or py.typed marker  [import-untyped]
2026-01-16T21:48:23.0399910Z google/cloud/vision_helpers/__init__.py:18: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @parthea, 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 and resolves existing mypy type checking errors within the google-cloud-monitoring package. The changes ensure that the type checker correctly handles the optional pandas dependency and has access to its type definitions, leading to a cleaner and more robust codebase without introducing new functionality.

Highlights

  • Mypy Type Hinting Fix: Added a type: ignore[assignment] comment to the pandas = None line in _dataframe.py to suppress a mypy error that occurs when the pandas library cannot be imported.
  • Mypy Dependency Update: Included pandas-stubs in the noxfile.py dependencies for the mypy session, providing necessary type information for the pandas library during type checking.
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.

@parthea parthea force-pushed the fix-google-cloud-monitoring-mypy branch from 4d28728 to f122d4d Compare January 30, 2026 17:51
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 fixes mypy errors by adding a type: ignore for an optional pandas import and including pandas-stubs in the mypy test environment. The changes are correct, but I've suggested a cleaner pattern for handling the optional import that avoids using type: ignore for better code clarity and maintainability.

import pandas
except ImportError: # pragma: NO COVER
pandas = None
pandas = None # type: ignore[assignment]
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

While using type: ignore is a valid way to resolve the mypy error, a more modern and clearer approach for handling optional dependencies is to use typing.TYPE_CHECKING. This avoids the need to suppress errors.

You can achieve this by:

  1. Adding an import guard at the top of the file:
from typing import TYPE_CHECKING

if TYPE_CHECKING:
    import pandas
  1. Removing the # type: ignore from this line. The try...except block for the import can remain as it is for the runtime logic.

This pattern makes the dependency explicit for static analysis tools while correctly handling its absence at runtime, improving overall code clarity and maintainability.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This suggestion results in the following error. The # type: ignore is needed based on local testing

.nox/mypy-3-14/lib/python3.14/site-packages/google/cloud/monitoring_v3/_dataframe.py:27: error: Incompatible types in assignment (expression has type "None", variable has type Module)  [assignment]
Found 1 error in 1 file (checked 93 source files)
nox > Command mypy -p google failed with exit code 1
nox > Session mypy-3.14 failed.

@parthea parthea marked this pull request as ready for review January 30, 2026 18:09
@parthea parthea requested review from a team as code owners January 30, 2026 18:09
Copy link
Contributor

@daniel-sanche daniel-sanche left a comment

Choose a reason for hiding this comment

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

LGTM

@parthea parthea merged commit 1f4c286 into main Jan 30, 2026
25 of 26 checks passed
@parthea parthea deleted the fix-google-cloud-monitoring-mypy branch January 30, 2026 19:33
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.

2 participants