Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ replacements:
count: 1
- paths: [
packages/google-cloud-speech/google/cloud/speech_v1/__init__.py,
packages/google-cloud-speech/google/cloud/speech_v1p1beta1/__init__.py,
]
before: |
\)
Expand All @@ -140,24 +141,16 @@ replacements:
)

from google.cloud.speech_v1.helpers import SpeechHelpers\n\n
class SpeechClient(SpeechHelpers, SpeechClient):
__doc__ = SpeechClient.__doc__\n\n
__all__ = (
count: 1
- paths: [
packages/google-cloud-speech/google/cloud/speech_v1p1beta1/__init__.py,
]
before: |
\)\n
__all__ = \(
after: |
)\n
from google.cloud.speech_v1.helpers import SpeechHelpers
\n
class SpeechClient(SpeechHelpers, SpeechClient):
# This class merges the auto-generated GAPIC client with handwritten helper methods.
# We ignore [misc] because mypy is flagging that both parent classes have a method
# named `streaming_recognize`,
# but their type signatures don't match.
# We ignore [no-redef] because of the name shadow with SpeechClient. We don't want
# to expose the GAPIC client without the helpers.
class SpeechClient(SpeechHelpers, SpeechClient): # type: ignore[no-redef, misc]
__doc__ = SpeechClient.__doc__\n\n
__all__ = (
count: 1
count: 2
- paths: [
packages/google-cloud-speech/google/cloud/speech/__init__.py,
]
Expand Down Expand Up @@ -301,3 +294,14 @@ replacements:
"pandas-stubs",
)
count: 1
- paths: [
packages/google-cloud-monitoring/noxfile.py,
]
before: |
"types-protobuf",
\ \)
after: |
"types-protobuf",
"pandas-stubs",
)
count: 1
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
try:
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.


from google.cloud import monitoring_v3

Expand Down
1 change: 1 addition & 0 deletions packages/google-cloud-monitoring/noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def mypy(session):
"mypy<1.16.0",
"types-requests",
"types-protobuf",
"pandas-stubs",
)
session.install(".")
session.run(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@

from __future__ import absolute_import

from typing import List

from google.api_core.protobuf_helpers import get_messages

from google.cloud.orgpolicy.v1 import orgpolicy_pb2

_modules = [orgpolicy_pb2]

names = []
names: List[str] = []

for module in _modules:
for name, message in get_messages(module).items():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,13 @@ def _get_version(dependency_name):
from google.cloud.speech_v1.helpers import SpeechHelpers


class SpeechClient(SpeechHelpers, SpeechClient):
# This class merges the auto-generated GAPIC client with handwritten helper methods.
# We ignore [misc] because mypy is flagging that both parent classes have a method
# named `streaming_recognize`,
# but their type signatures don't match.
# We ignore [no-redef] because of the name shadow with SpeechClient. We don't want
# to expose the GAPIC client without the helpers.
class SpeechClient(SpeechHelpers, SpeechClient): # type: ignore[no-redef, misc]
__doc__ = SpeechClient.__doc__


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,13 @@ def _get_version(dependency_name):
from google.cloud.speech_v1.helpers import SpeechHelpers


class SpeechClient(SpeechHelpers, SpeechClient):
# This class merges the auto-generated GAPIC client with handwritten helper methods.
# We ignore [misc] because mypy is flagging that both parent classes have a method
# named `streaming_recognize`,
# but their type signatures don't match.
# We ignore [no-redef] because of the name shadow with SpeechClient. We don't want
# to expose the GAPIC client without the helpers.
class SpeechClient(SpeechHelpers, SpeechClient): # type: ignore[no-redef, misc]
__doc__ = SpeechClient.__doc__


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from __future__ import absolute_import

from google.api_core import protobuf_helpers as protobuf
import proto
import proto # type: ignore


class VisionHelpers(object):
Expand Down
Loading