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
14 changes: 12 additions & 2 deletions gapic/schema/imp.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,21 @@ def __eq__(self, other) -> bool:
return self.package == other.package and self.module == other.module

def __str__(self) -> str:
# Determine if we need to suppress type checking for this import.
# We do this for protobuf generated files (_pb2) and api_core
# internals where type information might be missing or incomplete.
Copy link
Contributor

@daniel-sanche daniel-sanche Jan 30, 2026

Choose a reason for hiding this comment

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

Do we really need to do this in the generated code? Can't we configure it in mypy.ini?

Edit: Looking closer, it looks like this logic was already in place, you're just moving it around. Do you know if mypy.ini is an option though?

needs_type_ignore = self.module.endswith("_pb2") or "api_core" in self.package
if needs_type_ignore:
# Use 'import absolute.path as module' syntax to prevent Ruff/isort
# from combining this with other imports. This ensures the
# '# type: ignore' comment remains effective for this specific import.
full_module = ".".join(self.package + (self.module,))
alias = self.alias or self.module
return f"import {full_module} as {alias} # type: ignore"

answer = f"import {self.module}"
if self.package:
answer = f"from {'.'.join(self.package)} {answer}"
if self.alias:
answer += f" as {self.alias}"
if self.module.endswith("_pb2") or "api_core" in self.package:
answer += " # type: ignore"
return answer
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@
except AttributeError: # pragma: NO COVER
OptionalRetry = Union[retries.AsyncRetry, object, None] # type: ignore

from google.api_core import operation # type: ignore
from google.api_core import operation_async # type: ignore
from google.cloud.asset_v1.services.asset_service import pagers
from google.cloud.asset_v1.types import asset_service
from google.cloud.asset_v1.types import assets
from google.longrunning import operations_pb2 # type: ignore
from google.protobuf import field_mask_pb2 # type: ignore
from google.protobuf import timestamp_pb2 # type: ignore
from google.rpc import status_pb2 # type: ignore
from google.type import expr_pb2 # type: ignore
import google.api_core.operation as operation # type: ignore
import google.api_core.operation_async as operation_async # type: ignore
import google.protobuf.field_mask_pb2 as field_mask_pb2 # type: ignore
import google.protobuf.timestamp_pb2 as timestamp_pb2 # type: ignore
import google.rpc.status_pb2 as status_pb2 # type: ignore
import google.type.expr_pb2 as expr_pb2 # type: ignore
from .transports.base import AssetServiceTransport, DEFAULT_CLIENT_INFO
from .transports.grpc_asyncio import AssetServiceGrpcAsyncIOTransport
from .client import AssetServiceClient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,16 @@

_LOGGER = std_logging.getLogger(__name__)

from google.api_core import operation # type: ignore
from google.api_core import operation_async # type: ignore
from google.cloud.asset_v1.services.asset_service import pagers
from google.cloud.asset_v1.types import asset_service
from google.cloud.asset_v1.types import assets
from google.longrunning import operations_pb2 # type: ignore
from google.protobuf import field_mask_pb2 # type: ignore
from google.protobuf import timestamp_pb2 # type: ignore
from google.rpc import status_pb2 # type: ignore
from google.type import expr_pb2 # type: ignore
import google.api_core.operation as operation # type: ignore
import google.api_core.operation_async as operation_async # type: ignore
import google.protobuf.field_mask_pb2 as field_mask_pb2 # type: ignore
import google.protobuf.timestamp_pb2 as timestamp_pb2 # type: ignore
import google.rpc.status_pb2 as status_pb2 # type: ignore
import google.type.expr_pb2 as expr_pb2 # type: ignore
from .transports.base import AssetServiceTransport, DEFAULT_CLIENT_INFO
from .transports.grpc import AssetServiceGrpcTransport
from .transports.grpc_asyncio import AssetServiceGrpcAsyncIOTransport
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

from google.cloud.asset_v1.types import asset_service
from google.longrunning import operations_pb2 # type: ignore
from google.protobuf import empty_pb2 # type: ignore
import google.protobuf.empty_pb2 as empty_pb2 # type: ignore

DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(gapic_version=package_version.__version__)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

from google.cloud.asset_v1.types import asset_service
from google.longrunning import operations_pb2 # type: ignore
from google.protobuf import empty_pb2 # type: ignore
import google.protobuf.empty_pb2 as empty_pb2 # type: ignore
from .base import AssetServiceTransport, DEFAULT_CLIENT_INFO

try:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

from google.cloud.asset_v1.types import asset_service
from google.longrunning import operations_pb2 # type: ignore
from google.protobuf import empty_pb2 # type: ignore
import google.protobuf.empty_pb2 as empty_pb2 # type: ignore
from .base import AssetServiceTransport, DEFAULT_CLIENT_INFO
from .grpc import AssetServiceGrpcTransport

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@


from google.cloud.asset_v1.types import asset_service
from google.protobuf import empty_pb2 # type: ignore
import google.protobuf.empty_pb2 as empty_pb2 # type: ignore
from google.longrunning import operations_pb2 # type: ignore


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@


from google.cloud.asset_v1.types import asset_service
from google.protobuf import empty_pb2 # type: ignore
import google.protobuf.empty_pb2 as empty_pb2 # type: ignore
from google.longrunning import operations_pb2 # type: ignore


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
import proto # type: ignore

from google.cloud.asset_v1.types import assets as gca_assets
from google.iam.v1 import policy_pb2 # type: ignore
from google.protobuf import duration_pb2 # type: ignore
from google.protobuf import field_mask_pb2 # type: ignore
from google.protobuf import struct_pb2 # type: ignore
from google.protobuf import timestamp_pb2 # type: ignore
from google.rpc import status_pb2 # type: ignore
from google.type import expr_pb2 # type: ignore
import google.iam.v1.policy_pb2 as policy_pb2 # type: ignore
import google.protobuf.duration_pb2 as duration_pb2 # type: ignore
import google.protobuf.field_mask_pb2 as field_mask_pb2 # type: ignore
import google.protobuf.struct_pb2 as struct_pb2 # type: ignore
import google.protobuf.timestamp_pb2 as timestamp_pb2 # type: ignore
import google.rpc.status_pb2 as status_pb2 # type: ignore
import google.type.expr_pb2 as expr_pb2 # type: ignore


__protobuf__ = proto.module(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@

import proto # type: ignore

from google.cloud.orgpolicy.v1 import orgpolicy_pb2 # type: ignore
from google.cloud.osconfig.v1 import inventory_pb2 # type: ignore
from google.iam.v1 import policy_pb2 # type: ignore
from google.identity.accesscontextmanager.v1 import access_level_pb2 # type: ignore
from google.identity.accesscontextmanager.v1 import access_policy_pb2 # type: ignore
from google.identity.accesscontextmanager.v1 import service_perimeter_pb2 # type: ignore
from google.protobuf import struct_pb2 # type: ignore
from google.protobuf import timestamp_pb2 # type: ignore
from google.rpc import code_pb2 # type: ignore
import google.cloud.orgpolicy.v1.orgpolicy_pb2 as orgpolicy_pb2 # type: ignore
import google.cloud.osconfig.v1.inventory_pb2 as inventory_pb2 # type: ignore
import google.iam.v1.policy_pb2 as policy_pb2 # type: ignore
import google.identity.accesscontextmanager.v1.access_level_pb2 as access_level_pb2 # type: ignore
import google.identity.accesscontextmanager.v1.access_policy_pb2 as access_policy_pb2 # type: ignore
import google.identity.accesscontextmanager.v1.service_perimeter_pb2 as service_perimeter_pb2 # type: ignore
import google.protobuf.struct_pb2 as struct_pb2 # type: ignore
import google.protobuf.timestamp_pb2 as timestamp_pb2 # type: ignore
import google.rpc.code_pb2 as code_pb2 # type: ignore


__protobuf__ = proto.module(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
from google.api_core import grpc_helpers
from google.api_core import grpc_helpers_async
from google.api_core import operation
from google.api_core import operation_async # type: ignore
from google.api_core import operations_v1
from google.api_core import path_template
from google.api_core import retry as retries
Expand All @@ -63,12 +62,13 @@
from google.cloud.asset_v1.types import assets
from google.longrunning import operations_pb2 # type: ignore
from google.oauth2 import service_account
from google.protobuf import duration_pb2 # type: ignore
from google.protobuf import field_mask_pb2 # type: ignore
from google.protobuf import timestamp_pb2 # type: ignore
from google.rpc import status_pb2 # type: ignore
from google.type import expr_pb2 # type: ignore
import google.api_core.operation_async as operation_async # type: ignore
import google.auth
import google.protobuf.duration_pb2 as duration_pb2 # type: ignore
import google.protobuf.field_mask_pb2 as field_mask_pb2 # type: ignore
import google.protobuf.timestamp_pb2 as timestamp_pb2 # type: ignore
import google.rpc.status_pb2 as status_pb2 # type: ignore
import google.type.expr_pb2 as expr_pb2 # type: ignore



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
OptionalRetry = Union[retries.AsyncRetry, object, None] # type: ignore

from google.iam.credentials_v1.types import common
from google.protobuf import duration_pb2 # type: ignore
from google.protobuf import timestamp_pb2 # type: ignore
import google.protobuf.duration_pb2 as duration_pb2 # type: ignore
import google.protobuf.timestamp_pb2 as timestamp_pb2 # type: ignore
from .transports.base import IAMCredentialsTransport, DEFAULT_CLIENT_INFO
from .transports.grpc_asyncio import IAMCredentialsGrpcAsyncIOTransport
from .client import IAMCredentialsClient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
_LOGGER = std_logging.getLogger(__name__)

from google.iam.credentials_v1.types import common
from google.protobuf import duration_pb2 # type: ignore
from google.protobuf import timestamp_pb2 # type: ignore
import google.protobuf.duration_pb2 as duration_pb2 # type: ignore
import google.protobuf.timestamp_pb2 as timestamp_pb2 # type: ignore
from .transports.base import IAMCredentialsTransport, DEFAULT_CLIENT_INFO
from .transports.grpc import IAMCredentialsGrpcTransport
from .transports.grpc_asyncio import IAMCredentialsGrpcAsyncIOTransport
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

import proto # type: ignore

from google.protobuf import duration_pb2 # type: ignore
from google.protobuf import timestamp_pb2 # type: ignore
import google.protobuf.duration_pb2 as duration_pb2 # type: ignore
import google.protobuf.timestamp_pb2 as timestamp_pb2 # type: ignore


__protobuf__ = proto.module(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@
from google.iam.credentials_v1.services.iam_credentials import transports
from google.iam.credentials_v1.types import common
from google.oauth2 import service_account
from google.protobuf import duration_pb2 # type: ignore
from google.protobuf import timestamp_pb2 # type: ignore
import google.auth
import google.protobuf.duration_pb2 as duration_pb2 # type: ignore
import google.protobuf.timestamp_pb2 as timestamp_pb2 # type: ignore



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
except AttributeError: # pragma: NO COVER
OptionalRetry = Union[retries.AsyncRetry, object, None] # type: ignore

from google.api_core import operation # type: ignore
from google.api_core import operation_async # type: ignore
from google.cloud.eventarc_v1.services.eventarc import pagers
from google.cloud.eventarc_v1.types import channel
from google.cloud.eventarc_v1.types import channel as gce_channel
Expand All @@ -51,8 +49,10 @@
from google.iam.v1 import iam_policy_pb2 # type: ignore
from google.iam.v1 import policy_pb2 # type: ignore
from google.longrunning import operations_pb2 # type: ignore
from google.protobuf import field_mask_pb2 # type: ignore
from google.protobuf import timestamp_pb2 # type: ignore
import google.api_core.operation as operation # type: ignore
import google.api_core.operation_async as operation_async # type: ignore
import google.protobuf.field_mask_pb2 as field_mask_pb2 # type: ignore
import google.protobuf.timestamp_pb2 as timestamp_pb2 # type: ignore
from .transports.base import EventarcTransport, DEFAULT_CLIENT_INFO
from .transports.grpc_asyncio import EventarcGrpcAsyncIOTransport
from .client import EventarcClient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@

_LOGGER = std_logging.getLogger(__name__)

from google.api_core import operation # type: ignore
from google.api_core import operation_async # type: ignore
from google.cloud.eventarc_v1.services.eventarc import pagers
from google.cloud.eventarc_v1.types import channel
from google.cloud.eventarc_v1.types import channel as gce_channel
Expand All @@ -65,8 +63,10 @@
from google.iam.v1 import iam_policy_pb2 # type: ignore
from google.iam.v1 import policy_pb2 # type: ignore
from google.longrunning import operations_pb2 # type: ignore
from google.protobuf import field_mask_pb2 # type: ignore
from google.protobuf import timestamp_pb2 # type: ignore
import google.api_core.operation as operation # type: ignore
import google.api_core.operation_async as operation_async # type: ignore
import google.protobuf.field_mask_pb2 as field_mask_pb2 # type: ignore
import google.protobuf.timestamp_pb2 as timestamp_pb2 # type: ignore
from .transports.base import EventarcTransport, DEFAULT_CLIENT_INFO
from .transports.grpc import EventarcGrpcTransport
from .transports.grpc_asyncio import EventarcGrpcAsyncIOTransport
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import proto # type: ignore

from google.protobuf import timestamp_pb2 # type: ignore
import google.protobuf.timestamp_pb2 as timestamp_pb2 # type: ignore


__protobuf__ = proto.module(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import proto # type: ignore

from google.protobuf import timestamp_pb2 # type: ignore
import google.protobuf.timestamp_pb2 as timestamp_pb2 # type: ignore


__protobuf__ = proto.module(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
from google.cloud.eventarc_v1.types import discovery
from google.cloud.eventarc_v1.types import google_channel_config as gce_google_channel_config
from google.cloud.eventarc_v1.types import trigger as gce_trigger
from google.protobuf import field_mask_pb2 # type: ignore
from google.protobuf import timestamp_pb2 # type: ignore
import google.protobuf.field_mask_pb2 as field_mask_pb2 # type: ignore
import google.protobuf.timestamp_pb2 as timestamp_pb2 # type: ignore


__protobuf__ = proto.module(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import proto # type: ignore

from google.protobuf import timestamp_pb2 # type: ignore
import google.protobuf.timestamp_pb2 as timestamp_pb2 # type: ignore


__protobuf__ = proto.module(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

import proto # type: ignore

from google.protobuf import timestamp_pb2 # type: ignore
from google.rpc import code_pb2 # type: ignore
import google.protobuf.timestamp_pb2 as timestamp_pb2 # type: ignore
import google.rpc.code_pb2 as code_pb2 # type: ignore


__protobuf__ = proto.module(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
from google.api_core import grpc_helpers
from google.api_core import grpc_helpers_async
from google.api_core import operation
from google.api_core import operation_async # type: ignore
from google.api_core import operations_v1
from google.api_core import path_template
from google.api_core import retry as retries
Expand All @@ -75,10 +74,11 @@
from google.iam.v1 import policy_pb2 # type: ignore
from google.longrunning import operations_pb2 # type: ignore
from google.oauth2 import service_account
from google.protobuf import field_mask_pb2 # type: ignore
from google.protobuf import timestamp_pb2 # type: ignore
from google.rpc import code_pb2 # type: ignore
import google.api_core.operation_async as operation_async # type: ignore
import google.auth
import google.protobuf.field_mask_pb2 as field_mask_pb2 # type: ignore
import google.protobuf.timestamp_pb2 as timestamp_pb2 # type: ignore
import google.rpc.code_pb2 as code_pb2 # type: ignore



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@
except AttributeError: # pragma: NO COVER
OptionalRetry = Union[retries.AsyncRetry, object, None] # type: ignore

from google.api_core import operation # type: ignore
from google.api_core import operation_async # type: ignore
from google.cloud.logging_v2.services.config_service_v2 import pagers
from google.cloud.logging_v2.types import logging_config
from google.longrunning import operations_pb2 # type: ignore
from google.protobuf import empty_pb2 # type: ignore
from google.protobuf import field_mask_pb2 # type: ignore
from google.protobuf import timestamp_pb2 # type: ignore
import google.api_core.operation as operation # type: ignore
import google.api_core.operation_async as operation_async # type: ignore
import google.protobuf.empty_pb2 as empty_pb2 # type: ignore
import google.protobuf.field_mask_pb2 as field_mask_pb2 # type: ignore
import google.protobuf.timestamp_pb2 as timestamp_pb2 # type: ignore
from .transports.base import ConfigServiceV2Transport, DEFAULT_CLIENT_INFO
from .transports.grpc_asyncio import ConfigServiceV2GrpcAsyncIOTransport
from .client import ConfigServiceV2Client
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@

_LOGGER = std_logging.getLogger(__name__)

from google.api_core import operation # type: ignore
from google.api_core import operation_async # type: ignore
from google.cloud.logging_v2.services.config_service_v2 import pagers
from google.cloud.logging_v2.types import logging_config
from google.longrunning import operations_pb2 # type: ignore
from google.protobuf import empty_pb2 # type: ignore
from google.protobuf import field_mask_pb2 # type: ignore
from google.protobuf import timestamp_pb2 # type: ignore
import google.api_core.operation as operation # type: ignore
import google.api_core.operation_async as operation_async # type: ignore
import google.protobuf.empty_pb2 as empty_pb2 # type: ignore
import google.protobuf.field_mask_pb2 as field_mask_pb2 # type: ignore
import google.protobuf.timestamp_pb2 as timestamp_pb2 # type: ignore
from .transports.base import ConfigServiceV2Transport, DEFAULT_CLIENT_INFO
from .transports.grpc import ConfigServiceV2GrpcTransport
from .transports.grpc_asyncio import ConfigServiceV2GrpcAsyncIOTransport
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

from google.cloud.logging_v2.types import logging_config
from google.longrunning import operations_pb2 # type: ignore
from google.protobuf import empty_pb2 # type: ignore
import google.protobuf.empty_pb2 as empty_pb2 # type: ignore

DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(gapic_version=package_version.__version__)

Expand Down
Loading
Loading