From 8ea95e9b6d7e18bce51665c00970ad83fd401512 Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Tue, 20 Jan 2026 15:10:08 -0800 Subject: [PATCH 01/26] chore: unpin mypy check version --- gapic/templates/noxfile.py.j2 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/gapic/templates/noxfile.py.j2 b/gapic/templates/noxfile.py.j2 index 274ca368e0..afe8c4f953 100644 --- a/gapic/templates/noxfile.py.j2 +++ b/gapic/templates/noxfile.py.j2 @@ -91,8 +91,7 @@ nox.options.error_on_missing_interpreters = True def mypy(session): """Run the type checker.""" session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy - "mypy<1.16.0", + "mypy", "types-requests", "types-protobuf", ) From e42c8238c7ceb51ae57875d1eac1e6b899c8dff5 Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Tue, 20 Jan 2026 15:12:00 -0800 Subject: [PATCH 02/26] updated goldens --- tests/integration/goldens/asset/noxfile.py | 3 +-- tests/integration/goldens/credentials/noxfile.py | 3 +-- tests/integration/goldens/eventarc/noxfile.py | 3 +-- tests/integration/goldens/logging/noxfile.py | 3 +-- tests/integration/goldens/logging_internal/noxfile.py | 3 +-- tests/integration/goldens/redis/noxfile.py | 3 +-- tests/integration/goldens/redis_selective/noxfile.py | 3 +-- 7 files changed, 7 insertions(+), 14 deletions(-) diff --git a/tests/integration/goldens/asset/noxfile.py b/tests/integration/goldens/asset/noxfile.py index 487acba725..fb5acbaa8a 100755 --- a/tests/integration/goldens/asset/noxfile.py +++ b/tests/integration/goldens/asset/noxfile.py @@ -98,8 +98,7 @@ def mypy(session): """Run the type checker.""" session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy - "mypy<1.16.0", + "mypy", "types-requests", "types-protobuf", ) diff --git a/tests/integration/goldens/credentials/noxfile.py b/tests/integration/goldens/credentials/noxfile.py index af4ba3e285..096025b268 100755 --- a/tests/integration/goldens/credentials/noxfile.py +++ b/tests/integration/goldens/credentials/noxfile.py @@ -98,8 +98,7 @@ def mypy(session): """Run the type checker.""" session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy - "mypy<1.16.0", + "mypy", "types-requests", "types-protobuf", ) diff --git a/tests/integration/goldens/eventarc/noxfile.py b/tests/integration/goldens/eventarc/noxfile.py index c718640903..3f123b8d36 100755 --- a/tests/integration/goldens/eventarc/noxfile.py +++ b/tests/integration/goldens/eventarc/noxfile.py @@ -98,8 +98,7 @@ def mypy(session): """Run the type checker.""" session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy - "mypy<1.16.0", + "mypy", "types-requests", "types-protobuf", ) diff --git a/tests/integration/goldens/logging/noxfile.py b/tests/integration/goldens/logging/noxfile.py index 8bf90a69f4..778cbcbd60 100755 --- a/tests/integration/goldens/logging/noxfile.py +++ b/tests/integration/goldens/logging/noxfile.py @@ -98,8 +98,7 @@ def mypy(session): """Run the type checker.""" session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy - "mypy<1.16.0", + "mypy", "types-requests", "types-protobuf", ) diff --git a/tests/integration/goldens/logging_internal/noxfile.py b/tests/integration/goldens/logging_internal/noxfile.py index 8bf90a69f4..778cbcbd60 100755 --- a/tests/integration/goldens/logging_internal/noxfile.py +++ b/tests/integration/goldens/logging_internal/noxfile.py @@ -98,8 +98,7 @@ def mypy(session): """Run the type checker.""" session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy - "mypy<1.16.0", + "mypy", "types-requests", "types-protobuf", ) diff --git a/tests/integration/goldens/redis/noxfile.py b/tests/integration/goldens/redis/noxfile.py index 4349f5147d..d2fcf30488 100755 --- a/tests/integration/goldens/redis/noxfile.py +++ b/tests/integration/goldens/redis/noxfile.py @@ -98,8 +98,7 @@ def mypy(session): """Run the type checker.""" session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy - "mypy<1.16.0", + "mypy", "types-requests", "types-protobuf", ) diff --git a/tests/integration/goldens/redis_selective/noxfile.py b/tests/integration/goldens/redis_selective/noxfile.py index 4349f5147d..d2fcf30488 100755 --- a/tests/integration/goldens/redis_selective/noxfile.py +++ b/tests/integration/goldens/redis_selective/noxfile.py @@ -98,8 +98,7 @@ def mypy(session): """Run the type checker.""" session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy - "mypy<1.16.0", + "mypy", "types-requests", "types-protobuf", ) From 78470023298b9a5b56f0428dd8157374a3f9111c Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Tue, 20 Jan 2026 15:26:18 -0800 Subject: [PATCH 03/26] handle empty requests in mixins --- .../%sub/services/%service/_mixins.py.j2 | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/gapic/templates/%namespace/%name_%version/%sub/services/%service/_mixins.py.j2 b/gapic/templates/%namespace/%name_%version/%sub/services/%service/_mixins.py.j2 index 4bfc76e954..a5024e9f83 100644 --- a/gapic/templates/%namespace/%name_%version/%sub/services/%service/_mixins.py.j2 +++ b/gapic/templates/%namespace/%name_%version/%sub/services/%service/_mixins.py.j2 @@ -26,6 +26,8 @@ # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.ListOperationsRequest(**request) @@ -82,6 +84,8 @@ # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.GetOperationRequest(**request) @@ -141,6 +145,8 @@ # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.DeleteOperationRequest(**request) @@ -191,6 +197,8 @@ # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.CancelOperationRequest(**request) @@ -244,6 +252,8 @@ # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.WaitOperationRequest(**request) @@ -370,6 +380,8 @@ # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = iam_policy_pb2.SetIamPolicyRequest(**request) @@ -492,6 +504,8 @@ # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = iam_policy_pb2.GetIamPolicyRequest(**request) @@ -552,6 +566,8 @@ # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = iam_policy_pb2.TestIamPermissionsRequest(**request) @@ -611,6 +627,8 @@ # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = locations_pb2.GetLocationRequest(**request) @@ -666,6 +684,8 @@ # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = locations_pb2.ListLocationsRequest(**request) From e4767326bfdac9fd215c718cb49e0427afd57b1e Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Tue, 20 Jan 2026 15:28:49 -0800 Subject: [PATCH 04/26] allow dict as request type --- .../%sub/services/%service/_mixins.py.j2 | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/gapic/templates/%namespace/%name_%version/%sub/services/%service/_mixins.py.j2 b/gapic/templates/%namespace/%name_%version/%sub/services/%service/_mixins.py.j2 index a5024e9f83..1564a72632 100644 --- a/gapic/templates/%namespace/%name_%version/%sub/services/%service/_mixins.py.j2 +++ b/gapic/templates/%namespace/%name_%version/%sub/services/%service/_mixins.py.j2 @@ -3,7 +3,7 @@ {% if "ListOperations" in api.mixin_api_methods %} def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -61,7 +61,7 @@ {% if "GetOperation" in api.mixin_api_methods %} def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -118,7 +118,7 @@ {% if "DeleteOperation" in api.mixin_api_methods %} def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -171,7 +171,7 @@ {% if "CancelOperation" in api.mixin_api_methods %} def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -223,7 +223,7 @@ {% if "WaitOperation" in api.mixin_api_methods %} def wait_operation( self, - request: Optional[operations_pb2.WaitOperationRequest] = None, + request: Optional[Union[operations_pb2.WaitOperationRequest, dict] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -291,7 +291,7 @@ {% if "SetIamPolicy" in api.mixin_api_methods %} def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -414,7 +414,7 @@ {% if "GetIamPolicy" in api.mixin_api_methods %} def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -538,7 +538,7 @@ {% if "TestIamPermissions" in api.mixin_api_methods %} def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -604,7 +604,7 @@ {% if "GetLocation" in api.mixin_api_methods %} def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -661,7 +661,7 @@ {% if "ListLocations" in api.mixin_api_methods %} def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, From 3cb8e92f4cebc48f79e4dc62ab4a70edb3f91c18 Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Tue, 20 Jan 2026 15:51:21 -0800 Subject: [PATCH 05/26] handle none case in _get_default_mtls_endpoint --- .../%name/%version/%sub/services/%service/client.py.j2 | 3 +++ .../%name_%version/%sub/services/%service/client.py.j2 | 4 ++++ .../tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 | 2 ++ 3 files changed, 9 insertions(+) diff --git a/gapic/ads-templates/%namespace/%name/%version/%sub/services/%service/client.py.j2 b/gapic/ads-templates/%namespace/%name/%version/%sub/services/%service/client.py.j2 index 2b85bd9e76..cfd7486986 100644 --- a/gapic/ads-templates/%namespace/%name/%version/%sub/services/%service/client.py.j2 +++ b/gapic/ads-templates/%namespace/%name/%version/%sub/services/%service/client.py.j2 @@ -118,6 +118,9 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # could not parse api_endpoint; return as-is + return api_endpoint name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint diff --git a/gapic/templates/%namespace/%name_%version/%sub/services/%service/client.py.j2 b/gapic/templates/%namespace/%name_%version/%sub/services/%service/client.py.j2 index 0d60f47bb6..186aa2d3b9 100644 --- a/gapic/templates/%namespace/%name_%version/%sub/services/%service/client.py.j2 +++ b/gapic/templates/%namespace/%name_%version/%sub/services/%service/client.py.j2 @@ -161,6 +161,10 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # could not parse api_endpoint; return as-is + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint diff --git a/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 b/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 index c0e92cd9d6..3c1d4f7145 100644 --- a/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 +++ b/gapic/templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 @@ -146,6 +146,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert {{ service.client_name }}._get_default_mtls_endpoint(None) is None assert {{ service.client_name }}._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -153,6 +154,7 @@ def test__get_default_mtls_endpoint(): assert {{ service.client_name }}._get_default_mtls_endpoint(sandbox_endpoint) == sandbox_mtls_endpoint assert {{ service.client_name }}._get_default_mtls_endpoint(sandbox_mtls_endpoint) == sandbox_mtls_endpoint assert {{ service.client_name }}._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert {{ service.client_name }}._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): assert {{ service.client_name }}._read_environment_variables() == (False, "auto", None) From 76802137dabe58cd4bd40dee6d9b303957ce581d Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Tue, 20 Jan 2026 15:51:46 -0800 Subject: [PATCH 06/26] add check_untyped_defs --- gapic/templates/noxfile.py.j2 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gapic/templates/noxfile.py.j2 b/gapic/templates/noxfile.py.j2 index afe8c4f953..30fe883868 100644 --- a/gapic/templates/noxfile.py.j2 +++ b/gapic/templates/noxfile.py.j2 @@ -104,6 +104,8 @@ def mypy(session): {% else %} "{{ api.naming.versioned_module_name }}", {% endif %} + "--check-untyped-defs", + *session.posargs, ) From b8e99f4bbf7c80ba83b85d743695d8f708bc101e Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Tue, 20 Jan 2026 15:59:53 -0800 Subject: [PATCH 07/26] fixed binary dump format --- .../%name_%version/%sub/services/%service/_shared_macros.j2 | 2 +- .../%name_%version/%sub/services/%service/transports/grpc.py.j2 | 2 +- .../%sub/services/%service/transports/grpc_asyncio.py.j2 | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/gapic/templates/%namespace/%name_%version/%sub/services/%service/_shared_macros.j2 b/gapic/templates/%namespace/%name_%version/%sub/services/%service/_shared_macros.j2 index 6db274e82f..2ca7d14756 100644 --- a/gapic/templates/%namespace/%name_%version/%sub/services/%service/_shared_macros.j2 +++ b/gapic/templates/%namespace/%name_%version/%sub/services/%service/_shared_macros.j2 @@ -276,7 +276,7 @@ def _get_http_options(): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value diff --git a/gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/grpc.py.j2 b/gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/grpc.py.j2 index 23e7e19839..eb05f151c2 100644 --- a/gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/grpc.py.j2 +++ b/gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/grpc.py.j2 @@ -76,7 +76,7 @@ class _LoggingClientInterceptor(grpc.UnaryUnaryClientInterceptor): # pragma: NO elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, diff --git a/gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/grpc_asyncio.py.j2 b/gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/grpc_asyncio.py.j2 index d5f692442f..7d2994e443 100644 --- a/gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/grpc_asyncio.py.j2 +++ b/gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/grpc_asyncio.py.j2 @@ -81,7 +81,7 @@ class _LoggingClientAIOInterceptor(grpc.aio.UnaryUnaryClientInterceptor): # pra elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, From 75748ee2ea127f742bdb834a9c1bd91249cc8190 Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Tue, 20 Jan 2026 16:07:38 -0800 Subject: [PATCH 08/26] fixed inconsistent typing in api_endpoint --- .../%name/%version/%sub/services/%service/client.py.j2 | 4 ++-- .../%sub/services/%service/async_client.py.j2 | 2 +- .../%name_%version/%sub/services/%service/client.py.j2 | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/gapic/ads-templates/%namespace/%name/%version/%sub/services/%service/client.py.j2 b/gapic/ads-templates/%namespace/%name/%version/%sub/services/%service/client.py.j2 index cfd7486986..fd9300e562 100644 --- a/gapic/ads-templates/%namespace/%name/%version/%sub/services/%service/client.py.j2 +++ b/gapic/ads-templates/%namespace/%name/%version/%sub/services/%service/client.py.j2 @@ -100,7 +100,7 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta): This class implements API version {{ service.version }}.{% endif %}""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -108,7 +108,7 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optikonal[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint diff --git a/gapic/templates/%namespace/%name_%version/%sub/services/%service/async_client.py.j2 b/gapic/templates/%namespace/%name_%version/%sub/services/%service/async_client.py.j2 index 689d3e0620..ba3e7c4da6 100644 --- a/gapic/templates/%namespace/%name_%version/%sub/services/%service/async_client.py.j2 +++ b/gapic/templates/%namespace/%name_%version/%sub/services/%service/async_client.py.j2 @@ -162,7 +162,7 @@ class {{ service.async_client_name }}: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/gapic/templates/%namespace/%name_%version/%sub/services/%service/client.py.j2 b/gapic/templates/%namespace/%name_%version/%sub/services/%service/client.py.j2 index 186aa2d3b9..8508ed3f70 100644 --- a/gapic/templates/%namespace/%name_%version/%sub/services/%service/client.py.j2 +++ b/gapic/templates/%namespace/%name_%version/%sub/services/%service/client.py.j2 @@ -143,7 +143,7 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta): This class implements API version {{ service.version }}.{% endif %}""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -151,7 +151,7 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -391,7 +391,7 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta): return client_cert_source @staticmethod - def _get_api_endpoint(api_override, client_cert_source, universe_domain, use_mtls_endpoint): + def _get_api_endpoint(api_override, client_cert_source, universe_domain, use_mtls_endpoint) -> str: """Return the API endpoint used by the client. Args: @@ -477,7 +477,7 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta): error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: From 0118aaf09b7e0f5f5d520286e33db2be5edb5d89 Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Tue, 20 Jan 2026 16:13:46 -0800 Subject: [PATCH 09/26] fixed typo --- .../%name/%version/%sub/services/%service/client.py.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gapic/ads-templates/%namespace/%name/%version/%sub/services/%service/client.py.j2 b/gapic/ads-templates/%namespace/%name/%version/%sub/services/%service/client.py.j2 index fd9300e562..f973f5c26b 100644 --- a/gapic/ads-templates/%namespace/%name/%version/%sub/services/%service/client.py.j2 +++ b/gapic/ads-templates/%namespace/%name/%version/%sub/services/%service/client.py.j2 @@ -108,7 +108,7 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - Optikonal[str]: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint From fb5f0cbb92b1c6435cef3e56db1c4d6be14a3709 Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Tue, 20 Jan 2026 16:40:48 -0800 Subject: [PATCH 10/26] updated tests --- .../%name_%version/%sub/_test_mixins.py.j2 | 234 +++++++++ .../%name_%version/%sub/_test_mixins.py.j2 | 467 ++++++++++++++++++ 2 files changed, 701 insertions(+) diff --git a/gapic/ads-templates/tests/unit/gapic/%name_%version/%sub/_test_mixins.py.j2 b/gapic/ads-templates/tests/unit/gapic/%name_%version/%sub/_test_mixins.py.j2 index d7f8bb7e68..e19793749d 100644 --- a/gapic/ads-templates/tests/unit/gapic/%name_%version/%sub/_test_mixins.py.j2 +++ b/gapic/ads-templates/tests/unit/gapic/%name_%version/%sub/_test_mixins.py.j2 @@ -130,6 +130,24 @@ def test_delete_operation_from_dict(): ) call.assert_called() + +def test_delete_operation_flattened(): + client = {{ service.client_name }}( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + {% endif %} {# DeleteOperation #} {% if "CancelOperation" in api.mixin_api_methods %} @@ -196,6 +214,24 @@ def test_cancel_operation_from_dict(): } ) call.assert_called() + + +def test_cancel_operation_flattened(): + client = {{ service.client_name }}( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() {% endif %} {# CancelOperation #} {% if "WaitOperation" in api.mixin_api_methods %} @@ -264,6 +300,24 @@ def test_wait_operation_from_dict(): ) call.assert_called() + +def test_wait_operation_flattened(): + client = {{ service.client_name }}( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.wait_operation() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.WaitOperationRequest() + {% endif %} {# WaitOperation #} {% if "GetOperation" in api.mixin_api_methods %} @@ -333,6 +387,24 @@ def test_get_operation_from_dict(): call.assert_called() + +def test_get_operation_flattened(): + client = {{ service.client_name }}( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + {% endif %} {# GetOperation #} {% if "ListOperations" in api.mixin_api_methods %} @@ -401,6 +473,24 @@ def test_list_operations_from_dict(): call.assert_called() + +def test_list_operations_flattened(): + client = {{ service.client_name }}( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + {% endif %} {# ListOperations #} {% endif %} {# LRO #} @@ -471,6 +561,24 @@ def test_list_locations_from_dict(): ) call.assert_called() + +def test_list_locations_flattened(): + client = {{ service.client_name }}( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + {% endif %} {# ListLocations #} {# GetLocation #} @@ -537,6 +645,24 @@ def test_get_location_from_dict(): ) call.assert_called() + +def test_get_location_flattened(): + client = {{ service.client_name }}( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + {% endif %} {# GetLocation #} {% endif %} {# location_mixin #} @@ -614,6 +740,24 @@ def test_set_iam_policy_from_dict(): call.assert_called() +def test_set_iam_policy_flattened(): + client = {{ service.client_name }}( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + + client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + def test_get_iam_policy(transport: str = "grpc"): client = {{ service.client_name }}( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -687,6 +831,24 @@ def test_get_iam_policy_from_dict(): call.assert_called() +def test_get_iam_policy_flattened(): + client = {{ service.client_name }}( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + + client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + def test_test_iam_permissions(transport: str = "grpc"): client = {{ service.client_name }}( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -766,6 +928,24 @@ def test_test_iam_permissions_from_dict(): ) call.assert_called() + +def test_test_iam_permissions_flattened(): + client = {{ service.client_name }}( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.test_iam_permissions), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + {% endif %} {% if (not opts.add_iam_methods and api.has_iam_mixin) and 'grpc' in opts.transport %} @@ -839,6 +1019,24 @@ def test_set_iam_policy_from_dict(): } ) call.assert_called() + + +def test_set_iam_policy_flattened(): + client = {{ service.client_name }}( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + + client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() {% endif %} {% if "GetIamPolicy" in api.mixin_api_methods %} @@ -913,6 +1111,24 @@ def test_get_iam_policy_from_dict(): } ) call.assert_called() + + +def test_get_iam_policy_flattened(): + client = {{ service.client_name }}( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + + client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() {% endif %} {% if "TestIamPermissions" in api.mixin_api_methods %} @@ -994,6 +1210,24 @@ def test_test_iam_permissions_from_dict(): } ) call.assert_called() + + +def test_test_iam_permissions_flattened(): + client = {{ service.client_name }}( + credentials=ga_credentials.AnonymousCredentials(), + ) + + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.test_iam_permissions), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() {% endif %} {% endif %} diff --git a/gapic/templates/tests/unit/gapic/%name_%version/%sub/_test_mixins.py.j2 b/gapic/templates/tests/unit/gapic/%name_%version/%sub/_test_mixins.py.j2 index 169807a961..12e92fa192 100644 --- a/gapic/templates/tests/unit/gapic/%name_%version/%sub/_test_mixins.py.j2 +++ b/gapic/templates/tests/unit/gapic/%name_%version/%sub/_test_mixins.py.j2 @@ -127,6 +127,41 @@ def test_delete_operation_from_dict(): call.assert_called() {% endfor %} +{% for mode in ["", "async"] %} +{% if mode == "async" %} +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): +{% else %} +def test_delete_operation_flattened(): +{% endif %} + {% if mode == "" %} + client = {{ service.client_name }}( + credentials=ga_credentials.AnonymousCredentials(), + ) + {% else %} + client = {{ service.async_client_name }}( + credentials=async_anonymous_credentials(), + ) + {% endif %} + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + {% if mode == "" %} + call.return_value = None + + client.delete_operation() + {% else %} + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + None + ) + await client.delete_operation() + {% endif %} + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() +{% endfor %} + {% endif %} {# DeleteOperation #} {% if "CancelOperation" in api.mixin_api_methods %} @@ -255,6 +290,41 @@ def test_cancel_operation_from_dict(): {% endif %} call.assert_called() {% endfor %} + +{% for mode in ["", "async"] %} +{% if mode == "async" %} +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): +{% else %} +def test_cancel_operation_flattened(): +{% endif %} + {% if mode == "" %} + client = {{ service.client_name }}( + credentials=ga_credentials.AnonymousCredentials(), + ) + {% else %} + client = {{ service.async_client_name }}( + credentials=async_anonymous_credentials(), + ) + {% endif %} + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + {% if mode == "" %} + call.return_value = None + + client.cancel_operation() + {% else %} + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + None + ) + await client.cancel_operation() + {% endif %} + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() +{% endfor %} {% endif %} {# CancelOperation #} {% if "WaitOperation" in api.mixin_api_methods %} @@ -384,6 +454,41 @@ def test_wait_operation_from_dict(): call.assert_called() {% endfor %} +{% for mode in ["", "async"] %} +{% if mode == "async" %} +@pytest.mark.asyncio +async def test_wait_operation_flattened_async(): +{% else %} +def test_wait_operation_flattened(): +{% endif %} + {% if mode == "" %} + client = {{ service.client_name }}( + credentials=ga_credentials.AnonymousCredentials(), + ) + {% else %} + client = {{ service.async_client_name }}( + credentials=async_anonymous_credentials(), + ) + {% endif %} + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + {% if mode == "" %} + call.return_value = operations_pb2.Operation() + + client.wait_operation() + {% else %} + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.wait_operation() + {% endif %} + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.WaitOperationRequest() +{% endfor %} + {% endif %} {# WaitOperation #} {% if "GetOperation" in api.mixin_api_methods %} @@ -513,6 +618,41 @@ def test_get_operation_from_dict(): call.assert_called() {% endfor %} +{% for mode in ["", "async"] %} +{% if mode == "async" %} +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): +{% else %} +def test_get_operation_flattened(): +{% endif %} + {% if mode == "" %} + client = {{ service.client_name }}( + credentials=ga_credentials.AnonymousCredentials(), + ) + {% else %} + client = {{ service.async_client_name }}( + credentials=async_anonymous_credentials(), + ) + {% endif %} + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + {% if mode == "" %} + call.return_value = operations_pb2.Operation() + + client.get_operation() + {% else %} + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + {% endif %} + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() +{% endfor %} + {% endif %} {# GetOperation #} {% if "ListOperations" in api.mixin_api_methods %} @@ -642,6 +782,41 @@ def test_list_operations_from_dict(): call.assert_called() {% endfor %} +{% for mode in ["", "async"] %} +{% if mode == "async" %} +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): +{% else %} +def test_list_operations_flattened(): +{% endif %} + {% if mode == "" %} + client = {{ service.client_name }}( + credentials=ga_credentials.AnonymousCredentials(), + ) + {% else %} + client = {{ service.async_client_name }}( + credentials=async_anonymous_credentials(), + ) + {% endif %} + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + {% if mode == "" %} + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + {% else %} + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + {% endif %} + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() +{% endfor %} + {% endif %} {# ListOperations #} {% endif %} {# LRO #} @@ -777,6 +952,41 @@ def test_list_locations_from_dict(): call.assert_called() {% endfor %} +{% for mode in ["", "async"] %} +{% if mode == "async" %} +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): +{% else %} +def test_list_locations_flattened(): +{% endif %} + {% if mode == "" %} + client = {{ service.client_name }}( + credentials=ga_credentials.AnonymousCredentials(), + ) + {% else %} + client = {{ service.async_client_name }}( + credentials=async_anonymous_credentials(), + ) + {% endif %} + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + {% if mode == "" %} + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + {% else %} + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + {% endif %} + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() +{% endfor %} + {% endif %} {# ListLocations #} {# GetLocation #} @@ -907,6 +1117,41 @@ def test_get_location_from_dict(): call.assert_called() {% endfor %} +{% for mode in ["", "async"] %} +{% if mode == "async" %} +@pytest.mark.asyncio +async def test_get_location_flattened_async(): +{% else %} +def test_get_location_flattened(): +{% endif %} + {% if mode == "" %} + client = {{ service.client_name }}( + credentials=ga_credentials.AnonymousCredentials(), + ) + {% else %} + client = {{ service.async_client_name }}( + credentials=async_anonymous_credentials(), + ) + {% endif %} + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + {% if mode == "" %} + call.return_value = locations_pb2.Location() + + client.get_location() + {% else %} + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + {% endif %} + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() +{% endfor %} + {% endif %} {# GetLocation #} {% endif %} {# location_mixin #} @@ -1044,6 +1289,43 @@ async def test_set_iam_policy_from_dict_async(): call.assert_called() +def test_set_iam_policy_flattened(): + client = {{ service.client_name }}( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + + client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_set_iam_policy_flattened_async(): + client = {{ service.async_client_name }}( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy() + ) + + await client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + def test_get_iam_policy(transport: str = "grpc"): client = {{ service.client_name }}( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -1202,6 +1484,43 @@ async def test_get_iam_policy_from_dict_async(): call.assert_called() +def test_get_iam_policy_flattened(): + client = {{ service.client_name }}( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + + client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_get_iam_policy_flattened_async(): + client = {{ service.async_client_name }}( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy() + ) + + await client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + def test_test_iam_permissions(transport: str = "grpc"): client = {{ service.client_name }}( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -1367,6 +1686,43 @@ async def test_test_iam_permissions_from_dict_async(): ) call.assert_called() + +def test_test_iam_permissions_flattened(): + client = {{ service.client_name }}( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.test_iam_permissions), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + +@pytest.mark.asyncio +async def test_test_iam_permissions_flattened_async(): + client = {{ service.async_client_name }}( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.test_iam_permissions), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + await client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + {% endif %} {% if (not opts.add_iam_methods and api.has_iam_mixin) and ('grpc' in opts.transport or 'grpc_asyncio' in opts.transport) %} @@ -1501,6 +1857,43 @@ async def test_set_iam_policy_from_dict_async(): } ) call.assert_called() + + +def test_set_iam_policy_flattened(): + client = {{ service.client_name }}( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + + client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_set_iam_policy_flattened_async(): + client = {{ service.async_client_name }}( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy() + ) + + await client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() {% endif %} {% if "GetIamPolicy" in api.mixin_api_methods %} @@ -1660,6 +2053,43 @@ async def test_get_iam_policy_from_dict_async(): } ) call.assert_called() + + +def test_get_iam_policy_flattened(): + client = {{ service.client_name }}( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + + client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_get_iam_policy_flattened_async(): + client = {{ service.async_client_name }}( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy() + ) + + await client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() {% endif %} {% if "TestIamPermissions" in api.mixin_api_methods %} @@ -1827,5 +2257,42 @@ async def test_test_iam_permissions_from_dict_async(): } ) call.assert_called() + + +def test_test_iam_permissions_flattened(): + client = {{ service.client_name }}( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.test_iam_permissions), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + +@pytest.mark.asyncio +async def test_test_iam_permissions_flattened_async(): + client = {{ service.async_client_name }}( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.test_iam_permissions), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + await client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() {% endif %} {% endif %} From 7189985e2e6a35824000cb38a5eb896140d18f78 Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Tue, 20 Jan 2026 16:44:06 -0800 Subject: [PATCH 11/26] fixed missing bracket --- .../%sub/services/%service/_mixins.py.j2 | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/gapic/templates/%namespace/%name_%version/%sub/services/%service/_mixins.py.j2 b/gapic/templates/%namespace/%name_%version/%sub/services/%service/_mixins.py.j2 index 1564a72632..1876a630dd 100644 --- a/gapic/templates/%namespace/%name_%version/%sub/services/%service/_mixins.py.j2 +++ b/gapic/templates/%namespace/%name_%version/%sub/services/%service/_mixins.py.j2 @@ -3,7 +3,7 @@ {% if "ListOperations" in api.mixin_api_methods %} def list_operations( self, - request: Optional[Union[operations_pb2.ListOperationsRequest, dict] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -61,7 +61,7 @@ {% if "GetOperation" in api.mixin_api_methods %} def get_operation( self, - request: Optional[Union[operations_pb2.GetOperationRequest, dict] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -118,7 +118,7 @@ {% if "DeleteOperation" in api.mixin_api_methods %} def delete_operation( self, - request: Optional[Union[operations_pb2.DeleteOperationRequest, dict] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -171,7 +171,7 @@ {% if "CancelOperation" in api.mixin_api_methods %} def cancel_operation( self, - request: Optional[Union[operations_pb2.CancelOperationRequest, dict] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -223,7 +223,7 @@ {% if "WaitOperation" in api.mixin_api_methods %} def wait_operation( self, - request: Optional[Union[operations_pb2.WaitOperationRequest, dict] = None, + request: Optional[Union[operations_pb2.WaitOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -291,7 +291,7 @@ {% if "SetIamPolicy" in api.mixin_api_methods %} def set_iam_policy( self, - request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -414,7 +414,7 @@ {% if "GetIamPolicy" in api.mixin_api_methods %} def get_iam_policy( self, - request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -538,7 +538,7 @@ {% if "TestIamPermissions" in api.mixin_api_methods %} def test_iam_permissions( self, - request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -604,7 +604,7 @@ {% if "GetLocation" in api.mixin_api_methods %} def get_location( self, - request: Optional[Union[locations_pb2.GetLocationRequest, dict] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -661,7 +661,7 @@ {% if "ListLocations" in api.mixin_api_methods %} def list_locations( self, - request: Optional[Union[locations_pb2.ListLocationsRequest, dict] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, From ffd53ad7f28a44cab10b3483d6792089d75d2a0d Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Tue, 20 Jan 2026 16:49:34 -0800 Subject: [PATCH 12/26] updated mypy in other noxfiles --- gapic/ads-templates/noxfile.py.j2 | 2 ++ noxfile.py | 5 ++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/gapic/ads-templates/noxfile.py.j2 b/gapic/ads-templates/noxfile.py.j2 index 48646feb5e..075dc7eaee 100644 --- a/gapic/ads-templates/noxfile.py.j2 +++ b/gapic/ads-templates/noxfile.py.j2 @@ -52,5 +52,7 @@ def mypy(session): {% else %} '{{ api.naming.versioned_module_name }}', {% endif %} + "--check-untyped-defs", + *session.posargs, ) {% endblock %} diff --git a/noxfile.py b/noxfile.py index e99bfad597..4d40c4f979 100644 --- a/noxfile.py +++ b/noxfile.py @@ -607,8 +607,7 @@ def showcase_mypy( """Perform typecheck analysis on the generated Showcase library.""" session.install( - # TODO(https://github.com/googleapis/gapic-generator-python/issues/2410): Use the latest version of mypy - "mypy<1.16.0", + "mypy", "types-setuptools", "types-protobuf", "types-requests", @@ -619,7 +618,7 @@ def showcase_mypy( session.chdir(lib) # Run the tests. - session.run("mypy", "-p", "google") + session.run("mypy", "-p", "google", "--check-untyped-defs") @nox.session(python=NEWEST_PYTHON) From 4e8a7a6661242e52a5d34ab429e5147f5d041ea6 Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Tue, 20 Jan 2026 16:55:18 -0800 Subject: [PATCH 13/26] added changes to ads-templates --- .../%sub/services/%service/_mixins.py.j2 | 40 ++++++++++++++----- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/gapic/ads-templates/%namespace/%name/%version/%sub/services/%service/_mixins.py.j2 b/gapic/ads-templates/%namespace/%name/%version/%sub/services/%service/_mixins.py.j2 index 6dd04dfb18..a76224af83 100644 --- a/gapic/ads-templates/%namespace/%name/%version/%sub/services/%service/_mixins.py.j2 +++ b/gapic/ads-templates/%namespace/%name/%version/%sub/services/%service/_mixins.py.j2 @@ -3,7 +3,7 @@ {% if "ListOperations" in api.mixin_api_methods %} def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -27,6 +27,8 @@ # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.ListOperationsRequest(**request) @@ -53,7 +55,7 @@ {% if "GetOperation" in api.mixin_api_methods %} def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -77,6 +79,8 @@ # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.GetOperationRequest(**request) @@ -102,7 +106,7 @@ {% if "DeleteOperation" in api.mixin_api_methods %} def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -130,6 +134,8 @@ # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.DeleteOperationRequest(**request) @@ -151,7 +157,7 @@ {% if "CancelOperation" in api.mixin_api_methods %} def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -178,6 +184,8 @@ # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.CancelOperationRequest(**request) @@ -199,7 +207,7 @@ {% if "WaitOperation" in api.mixin_api_methods %} def wait_operation( self, - request: Optional[operations_pb2.WaitOperationRequest] = None, + request: Optional[Union[operations_pb2.WaitOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -229,6 +237,8 @@ # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.WaitOperationRequest(**request) @@ -254,7 +264,7 @@ {% if "SetIamPolicy" in api.mixin_api_methods %} def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -344,6 +354,8 @@ # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = iam_policy_pb2.SetIamPolicyRequest(**request) @@ -369,7 +381,7 @@ {% if "GetIamPolicy" in api.mixin_api_methods %} def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -460,6 +472,8 @@ # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = iam_policy_pb2.GetIamPolicyRequest(**request) @@ -485,7 +499,7 @@ {% if "TestIamPermissions" in api.mixin_api_methods %} def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -514,6 +528,8 @@ # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = iam_policy_pb2.TestIamPermissionsRequest(**request) @@ -543,7 +559,7 @@ {% if "GetLocation" in api.mixin_api_methods %} def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -567,6 +583,8 @@ # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = locations_pb2.GetLocationRequest(**request) @@ -592,7 +610,7 @@ {% if "ListLocations" in api.mixin_api_methods %} def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -616,6 +634,8 @@ # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = locations_pb2.ListLocationsRequest(**request) From 6664f75577f7038867af5d98e52092b85639f4ed Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Tue, 20 Jan 2026 17:06:02 -0800 Subject: [PATCH 14/26] updated ads template tests --- .../tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gapic/ads-templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 b/gapic/ads-templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 index ac385e285d..39d5fa7d35 100644 --- a/gapic/ads-templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 +++ b/gapic/ads-templates/tests/unit/gapic/%name_%version/%sub/test_%service.py.j2 @@ -94,6 +94,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert {{ service.client_name }}._get_default_mtls_endpoint(None) is None assert {{ service.client_name }}._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -101,6 +102,7 @@ def test__get_default_mtls_endpoint(): assert {{ service.client_name }}._get_default_mtls_endpoint(sandbox_endpoint) == sandbox_mtls_endpoint assert {{ service.client_name }}._get_default_mtls_endpoint(sandbox_mtls_endpoint) == sandbox_mtls_endpoint assert {{ service.client_name }}._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert {{ service.client_name }}._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint @pytest.mark.parametrize("client_class,transport_name", [ From f394d57c2ac4f37f2804996450b46f1f2908ac5e Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Tue, 20 Jan 2026 17:11:53 -0800 Subject: [PATCH 15/26] updated async mixins --- .../services/%service/_async_mixins.py.j2 | 40 ++++++++++++++----- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/gapic/templates/%namespace/%name_%version/%sub/services/%service/_async_mixins.py.j2 b/gapic/templates/%namespace/%name_%version/%sub/services/%service/_async_mixins.py.j2 index 60b8f0a7e9..7b244b67c0 100644 --- a/gapic/templates/%namespace/%name_%version/%sub/services/%service/_async_mixins.py.j2 +++ b/gapic/templates/%namespace/%name_%version/%sub/services/%service/_async_mixins.py.j2 @@ -5,7 +5,7 @@ {% if "ListOperations" in api.mixin_api_methods %} async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -28,6 +28,8 @@ # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.ListOperationsRequest(**request) @@ -57,7 +59,7 @@ {% if "GetOperation" in api.mixin_api_methods %} async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -80,6 +82,8 @@ # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.GetOperationRequest(**request) @@ -108,7 +112,7 @@ {% if "DeleteOperation" in api.mixin_api_methods %} async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -135,6 +139,8 @@ # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.DeleteOperationRequest(**request) @@ -159,7 +165,7 @@ {% if "CancelOperation" in api.mixin_api_methods %} async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -185,6 +191,8 @@ # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.CancelOperationRequest(**request) @@ -209,7 +217,7 @@ {% if "WaitOperation" in api.mixin_api_methods %} async def wait_operation( self, - request: Optional[operations_pb2.WaitOperationRequest] = None, + request: Optional[Union[operations_pb2.WaitOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -238,6 +246,8 @@ # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.WaitOperationRequest(**request) @@ -271,7 +281,7 @@ {% if "SetIamPolicy" in api.mixin_api_methods %} async def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -360,6 +370,8 @@ # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = iam_policy_pb2.SetIamPolicyRequest(**request) @@ -388,7 +400,7 @@ {% if "GetIamPolicy" in api.mixin_api_methods %} async def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -478,6 +490,8 @@ # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = iam_policy_pb2.GetIamPolicyRequest(**request) @@ -506,7 +520,7 @@ {% if "TestIamPermissions" in api.mixin_api_methods %} async def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -534,6 +548,8 @@ # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = iam_policy_pb2.TestIamPermissionsRequest(**request) @@ -566,7 +582,7 @@ {% if "GetLocation" in api.mixin_api_methods %} async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -589,6 +605,8 @@ # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = locations_pb2.GetLocationRequest(**request) @@ -617,7 +635,7 @@ {% if "ListLocations" in api.mixin_api_methods %} async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -640,6 +658,8 @@ # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = locations_pb2.ListLocationsRequest(**request) From 7b7c8dc3ff0a627422bb421b4a5a05278467482d Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Tue, 20 Jan 2026 17:21:01 -0800 Subject: [PATCH 16/26] updated iam templates --- .../%sub/services/%service/client.py.j2 | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/gapic/templates/%namespace/%name_%version/%sub/services/%service/client.py.j2 b/gapic/templates/%namespace/%name_%version/%sub/services/%service/client.py.j2 index 8508ed3f70..9a22c55ece 100644 --- a/gapic/templates/%namespace/%name_%version/%sub/services/%service/client.py.j2 +++ b/gapic/templates/%namespace/%name_%version/%sub/services/%service/client.py.j2 @@ -708,7 +708,7 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta): {% if opts.add_iam_methods %} def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -797,6 +797,8 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta): # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = iam_policy_pb2.SetIamPolicyRequest(**request) @@ -831,7 +833,7 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta): def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -921,6 +923,8 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta): # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = iam_policy_pb2.GetIamPolicyRequest(**request) @@ -955,7 +959,7 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta): def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -983,6 +987,8 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta): # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = iam_policy_pb2.TestIamPermissionsRequest(**request) From 96f14a3c63351504d3b9d397cf0bef26f17f4c7d Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Tue, 20 Jan 2026 17:26:21 -0800 Subject: [PATCH 17/26] updated async iam methods --- .../%sub/services/%service/async_client.py.j2 | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/gapic/templates/%namespace/%name_%version/%sub/services/%service/async_client.py.j2 b/gapic/templates/%namespace/%name_%version/%sub/services/%service/async_client.py.j2 index ba3e7c4da6..e3752a8a55 100644 --- a/gapic/templates/%namespace/%name_%version/%sub/services/%service/async_client.py.j2 +++ b/gapic/templates/%namespace/%name_%version/%sub/services/%service/async_client.py.j2 @@ -442,7 +442,7 @@ class {{ service.async_client_name }}: {% if opts.add_iam_methods %} async def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -530,6 +530,8 @@ class {{ service.async_client_name }}: # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = iam_policy_pb2.SetIamPolicyRequest(**request) @@ -554,7 +556,7 @@ class {{ service.async_client_name }}: async def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -644,6 +646,8 @@ class {{ service.async_client_name }}: # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = iam_policy_pb2.GetIamPolicyRequest(**request) @@ -668,7 +672,7 @@ class {{ service.async_client_name }}: async def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -696,6 +700,8 @@ class {{ service.async_client_name }}: # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = iam_policy_pb2.TestIamPermissionsRequest(**request) From 7264e6319d0ccff3d12fb17c9f3758642ada89d6 Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Tue, 20 Jan 2026 17:29:48 -0800 Subject: [PATCH 18/26] updated iam methods in ads-template --- .../%version/%sub/services/%service/client.py.j2 | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/gapic/ads-templates/%namespace/%name/%version/%sub/services/%service/client.py.j2 b/gapic/ads-templates/%namespace/%name/%version/%sub/services/%service/client.py.j2 index f973f5c26b..29f1d5721c 100644 --- a/gapic/ads-templates/%namespace/%name/%version/%sub/services/%service/client.py.j2 +++ b/gapic/ads-templates/%namespace/%name/%version/%sub/services/%service/client.py.j2 @@ -543,7 +543,7 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta): {% if opts.add_iam_methods %} def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -633,6 +633,8 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta): # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = iam_policy_pb2.SetIamPolicyRequest(**request) @@ -660,7 +662,7 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta): def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -750,6 +752,8 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta): # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = iam_policy_pb2.GetIamPolicyRequest(**request) @@ -777,7 +781,7 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta): def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -806,6 +810,8 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta): # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = iam_policy_pb2.TestIamPermissionsRequest(**request) From cbe19db1911de9b71af894a87b4de470ea84f89a Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Tue, 20 Jan 2026 18:31:34 -0800 Subject: [PATCH 19/26] updated some goldens --- .../services/asset_service/async_client.py | 6 +- .../asset_v1/services/asset_service/client.py | 16 +- .../services/asset_service/transports/grpc.py | 4 +- .../asset_service/transports/grpc_asyncio.py | 4 +- tests/integration/goldens/asset/noxfile.py | 2 + .../unit/gapic/asset_v1/test_asset_service.py | 33 +++ .../services/iam_credentials/async_client.py | 2 +- .../services/iam_credentials/client.py | 12 +- .../iam_credentials/transports/grpc.py | 4 +- .../transports/grpc_asyncio.py | 4 +- .../goldens/credentials/noxfile.py | 2 + .../credentials_v1/test_iam_credentials.py | 2 + .../config_service_v2/async_client.py | 14 +- .../services/config_service_v2/client.py | 24 +- .../config_service_v2/transports/grpc.py | 4 +- .../transports/grpc_asyncio.py | 4 +- .../logging_service_v2/async_client.py | 14 +- .../services/logging_service_v2/client.py | 24 +- .../logging_service_v2/transports/grpc.py | 4 +- .../transports/grpc_asyncio.py | 4 +- .../metrics_service_v2/async_client.py | 14 +- .../services/metrics_service_v2/client.py | 24 +- .../metrics_service_v2/transports/grpc.py | 4 +- .../transports/grpc_asyncio.py | 4 +- .../goldens/logging_internal/noxfile.py | 2 + .../logging_v2/test_config_service_v2.py | 95 ++++++++ .../logging_v2/test_logging_service_v2.py | 95 ++++++++ .../logging_v2/test_metrics_service_v2.py | 95 ++++++++ .../services/cloud_redis/async_client.py | 30 ++- .../redis_v1/services/cloud_redis/client.py | 40 +++- .../services/cloud_redis/transports/grpc.py | 4 +- .../cloud_redis/transports/grpc_asyncio.py | 4 +- .../goldens/redis_selective/noxfile.py | 2 + .../unit/gapic/redis_v1/test_cloud_redis.py | 219 ++++++++++++++++++ 34 files changed, 727 insertions(+), 88 deletions(-) diff --git a/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/async_client.py b/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/async_client.py index 38379ce9d7..8ae1ec3272 100755 --- a/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/async_client.py +++ b/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/async_client.py @@ -170,7 +170,7 @@ def transport(self) -> AssetServiceTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -3154,7 +3154,7 @@ async def sample_analyze_org_policy_governed_assets(): async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3180,6 +3180,8 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.GetOperationRequest(**request) diff --git a/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/client.py b/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/client.py index 843790205a..b771d004be 100755 --- a/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/client.py +++ b/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/client.py @@ -101,7 +101,7 @@ class AssetServiceClient(metaclass=AssetServiceClientMeta): """Asset service definition.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -109,7 +109,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -119,6 +119,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # could not parse api_endpoint; return as-is + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -446,7 +450,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): return client_cert_source @staticmethod - def _get_api_endpoint(api_override, client_cert_source, universe_domain, use_mtls_endpoint): + def _get_api_endpoint(api_override, client_cert_source, universe_domain, use_mtls_endpoint) -> str: """Return the API endpoint used by the client. Args: @@ -532,7 +536,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -3576,7 +3580,7 @@ def __exit__(self, type, value, traceback): def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3602,6 +3606,8 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.GetOperationRequest(**request) diff --git a/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/transports/grpc.py b/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/transports/grpc.py index 1edf735194..feb274eb72 100755 --- a/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/transports/grpc.py +++ b/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -86,7 +86,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, diff --git a/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/transports/grpc_asyncio.py b/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/transports/grpc_asyncio.py index a2b4aeb11a..b833df6e22 100755 --- a/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/transports/grpc_asyncio.py +++ b/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/transports/grpc_asyncio.py @@ -59,7 +59,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, diff --git a/tests/integration/goldens/asset/noxfile.py b/tests/integration/goldens/asset/noxfile.py index fb5acbaa8a..ef838a250b 100755 --- a/tests/integration/goldens/asset/noxfile.py +++ b/tests/integration/goldens/asset/noxfile.py @@ -107,6 +107,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) diff --git a/tests/integration/goldens/asset/tests/unit/gapic/asset_v1/test_asset_service.py b/tests/integration/goldens/asset/tests/unit/gapic/asset_v1/test_asset_service.py index bd17439996..4f8ed36647 100755 --- a/tests/integration/goldens/asset/tests/unit/gapic/asset_v1/test_asset_service.py +++ b/tests/integration/goldens/asset/tests/unit/gapic/asset_v1/test_asset_service.py @@ -114,6 +114,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert AssetServiceClient._get_default_mtls_endpoint(None) is None assert AssetServiceClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -121,6 +122,7 @@ def test__get_default_mtls_endpoint(): assert AssetServiceClient._get_default_mtls_endpoint(sandbox_endpoint) == sandbox_mtls_endpoint assert AssetServiceClient._get_default_mtls_endpoint(sandbox_mtls_endpoint) == sandbox_mtls_endpoint assert AssetServiceClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert AssetServiceClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): assert AssetServiceClient._read_environment_variables() == (False, "auto", None) @@ -18385,6 +18387,37 @@ async def test_get_operation_from_dict_async(): ) call.assert_called() +def test_get_operation_flattened(): + client = AssetServiceClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = AssetServiceAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + def test_transport_close_grpc(): client = AssetServiceClient( diff --git a/tests/integration/goldens/credentials/google/iam/credentials_v1/services/iam_credentials/async_client.py b/tests/integration/goldens/credentials/google/iam/credentials_v1/services/iam_credentials/async_client.py index eac708473c..529bffc55a 100755 --- a/tests/integration/goldens/credentials/google/iam/credentials_v1/services/iam_credentials/async_client.py +++ b/tests/integration/goldens/credentials/google/iam/credentials_v1/services/iam_credentials/async_client.py @@ -161,7 +161,7 @@ def transport(self) -> IAMCredentialsTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/tests/integration/goldens/credentials/google/iam/credentials_v1/services/iam_credentials/client.py b/tests/integration/goldens/credentials/google/iam/credentials_v1/services/iam_credentials/client.py index 4f2406bad6..61ea24f38e 100755 --- a/tests/integration/goldens/credentials/google/iam/credentials_v1/services/iam_credentials/client.py +++ b/tests/integration/goldens/credentials/google/iam/credentials_v1/services/iam_credentials/client.py @@ -104,7 +104,7 @@ class IAMCredentialsClient(metaclass=IAMCredentialsClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -112,7 +112,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -122,6 +122,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # could not parse api_endpoint; return as-is + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -383,7 +387,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): return client_cert_source @staticmethod - def _get_api_endpoint(api_override, client_cert_source, universe_domain, use_mtls_endpoint): + def _get_api_endpoint(api_override, client_cert_source, universe_domain, use_mtls_endpoint) -> str: """Return the API endpoint used by the client. Args: @@ -469,7 +473,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: diff --git a/tests/integration/goldens/credentials/google/iam/credentials_v1/services/iam_credentials/transports/grpc.py b/tests/integration/goldens/credentials/google/iam/credentials_v1/services/iam_credentials/transports/grpc.py index 5baaeb8e5e..6a49e1edff 100755 --- a/tests/integration/goldens/credentials/google/iam/credentials_v1/services/iam_credentials/transports/grpc.py +++ b/tests/integration/goldens/credentials/google/iam/credentials_v1/services/iam_credentials/transports/grpc.py @@ -52,7 +52,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -83,7 +83,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, diff --git a/tests/integration/goldens/credentials/google/iam/credentials_v1/services/iam_credentials/transports/grpc_asyncio.py b/tests/integration/goldens/credentials/google/iam/credentials_v1/services/iam_credentials/transports/grpc_asyncio.py index a793abd09c..4512b4625a 100755 --- a/tests/integration/goldens/credentials/google/iam/credentials_v1/services/iam_credentials/transports/grpc_asyncio.py +++ b/tests/integration/goldens/credentials/google/iam/credentials_v1/services/iam_credentials/transports/grpc_asyncio.py @@ -56,7 +56,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -87,7 +87,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, diff --git a/tests/integration/goldens/credentials/noxfile.py b/tests/integration/goldens/credentials/noxfile.py index 096025b268..aff5c15633 100755 --- a/tests/integration/goldens/credentials/noxfile.py +++ b/tests/integration/goldens/credentials/noxfile.py @@ -107,6 +107,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) diff --git a/tests/integration/goldens/credentials/tests/unit/gapic/credentials_v1/test_iam_credentials.py b/tests/integration/goldens/credentials/tests/unit/gapic/credentials_v1/test_iam_credentials.py index d9f2f0a4be..9624eeec05 100755 --- a/tests/integration/goldens/credentials/tests/unit/gapic/credentials_v1/test_iam_credentials.py +++ b/tests/integration/goldens/credentials/tests/unit/gapic/credentials_v1/test_iam_credentials.py @@ -104,6 +104,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert IAMCredentialsClient._get_default_mtls_endpoint(None) is None assert IAMCredentialsClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -111,6 +112,7 @@ def test__get_default_mtls_endpoint(): assert IAMCredentialsClient._get_default_mtls_endpoint(sandbox_endpoint) == sandbox_mtls_endpoint assert IAMCredentialsClient._get_default_mtls_endpoint(sandbox_mtls_endpoint) == sandbox_mtls_endpoint assert IAMCredentialsClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert IAMCredentialsClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): assert IAMCredentialsClient._read_environment_variables() == (False, "auto", None) diff --git a/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/config_service_v2/async_client.py b/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/config_service_v2/async_client.py index ef5a9151a1..39e0cf65e4 100755 --- a/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/config_service_v2/async_client.py +++ b/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/config_service_v2/async_client.py @@ -168,7 +168,7 @@ def transport(self) -> ConfigServiceV2Transport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -3898,7 +3898,7 @@ async def sample_copy_log_entries(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3924,6 +3924,8 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.ListOperationsRequest(**request) @@ -3950,7 +3952,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3976,6 +3978,8 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.GetOperationRequest(**request) @@ -4002,7 +4006,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4031,6 +4035,8 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.CancelOperationRequest(**request) diff --git a/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/config_service_v2/client.py b/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/config_service_v2/client.py index 7889ba044b..6c4eaf85e4 100755 --- a/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/config_service_v2/client.py +++ b/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/config_service_v2/client.py @@ -97,7 +97,7 @@ class BaseConfigServiceV2Client(metaclass=BaseConfigServiceV2ClientMeta): """Service for configuring sinks used to route log entries.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -105,7 +105,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -115,6 +115,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # could not parse api_endpoint; return as-is + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -442,7 +446,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): return client_cert_source @staticmethod - def _get_api_endpoint(api_override, client_cert_source, universe_domain, use_mtls_endpoint): + def _get_api_endpoint(api_override, client_cert_source, universe_domain, use_mtls_endpoint) -> str: """Return the API endpoint used by the client. Args: @@ -528,7 +532,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -4316,7 +4320,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4342,6 +4346,8 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.ListOperationsRequest(**request) @@ -4372,7 +4378,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4398,6 +4404,8 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.GetOperationRequest(**request) @@ -4428,7 +4436,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4457,6 +4465,8 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.CancelOperationRequest(**request) diff --git a/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/config_service_v2/transports/grpc.py b/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/config_service_v2/transports/grpc.py index ac3a4393a8..8ad6eaad62 100755 --- a/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/config_service_v2/transports/grpc.py +++ b/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/config_service_v2/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -86,7 +86,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, diff --git a/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/config_service_v2/transports/grpc_asyncio.py b/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/config_service_v2/transports/grpc_asyncio.py index fc7af0c06b..7aacec1ecf 100755 --- a/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/config_service_v2/transports/grpc_asyncio.py +++ b/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/config_service_v2/transports/grpc_asyncio.py @@ -59,7 +59,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, diff --git a/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/logging_service_v2/async_client.py b/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/logging_service_v2/async_client.py index f84e9f6ec5..953c59eb4a 100755 --- a/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/logging_service_v2/async_client.py +++ b/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/logging_service_v2/async_client.py @@ -153,7 +153,7 @@ def transport(self) -> LoggingServiceV2Transport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1013,7 +1013,7 @@ def request_generator(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1039,6 +1039,8 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.ListOperationsRequest(**request) @@ -1065,7 +1067,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1091,6 +1093,8 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.GetOperationRequest(**request) @@ -1117,7 +1121,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1146,6 +1150,8 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.CancelOperationRequest(**request) diff --git a/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/logging_service_v2/client.py b/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/logging_service_v2/client.py index 8c37951cb5..3c2e5510eb 100755 --- a/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/logging_service_v2/client.py +++ b/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/logging_service_v2/client.py @@ -94,7 +94,7 @@ class LoggingServiceV2Client(metaclass=LoggingServiceV2ClientMeta): """Service for ingesting and querying logs.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -102,7 +102,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -112,6 +112,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # could not parse api_endpoint; return as-is + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -373,7 +377,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): return client_cert_source @staticmethod - def _get_api_endpoint(api_override, client_cert_source, universe_domain, use_mtls_endpoint): + def _get_api_endpoint(api_override, client_cert_source, universe_domain, use_mtls_endpoint) -> str: """Return the API endpoint used by the client. Args: @@ -459,7 +463,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1390,7 +1394,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1416,6 +1420,8 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.ListOperationsRequest(**request) @@ -1446,7 +1452,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1472,6 +1478,8 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.GetOperationRequest(**request) @@ -1502,7 +1510,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1531,6 +1539,8 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.CancelOperationRequest(**request) diff --git a/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/logging_service_v2/transports/grpc.py b/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/logging_service_v2/transports/grpc.py index 8edc617027..86a6f3711d 100755 --- a/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/logging_service_v2/transports/grpc.py +++ b/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/logging_service_v2/transports/grpc.py @@ -54,7 +54,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -85,7 +85,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, diff --git a/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/logging_service_v2/transports/grpc_asyncio.py b/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/logging_service_v2/transports/grpc_asyncio.py index 92aa1d5256..2dced8c696 100755 --- a/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/logging_service_v2/transports/grpc_asyncio.py +++ b/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/logging_service_v2/transports/grpc_asyncio.py @@ -58,7 +58,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -89,7 +89,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, diff --git a/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/metrics_service_v2/async_client.py b/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/metrics_service_v2/async_client.py index 5f0bf0c782..93835fcc77 100755 --- a/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/metrics_service_v2/async_client.py +++ b/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/metrics_service_v2/async_client.py @@ -154,7 +154,7 @@ def transport(self) -> MetricsServiceV2Transport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -864,7 +864,7 @@ async def sample_delete_log_metric(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -890,6 +890,8 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.ListOperationsRequest(**request) @@ -916,7 +918,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -942,6 +944,8 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.GetOperationRequest(**request) @@ -968,7 +972,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -997,6 +1001,8 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.CancelOperationRequest(**request) diff --git a/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/metrics_service_v2/client.py b/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/metrics_service_v2/client.py index 479ae7c032..9331bc5b91 100755 --- a/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/metrics_service_v2/client.py +++ b/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/metrics_service_v2/client.py @@ -95,7 +95,7 @@ class BaseMetricsServiceV2Client(metaclass=BaseMetricsServiceV2ClientMeta): """Service for configuring logs-based metrics.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -103,7 +103,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -113,6 +113,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # could not parse api_endpoint; return as-is + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -374,7 +378,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): return client_cert_source @staticmethod - def _get_api_endpoint(api_override, client_cert_source, universe_domain, use_mtls_endpoint): + def _get_api_endpoint(api_override, client_cert_source, universe_domain, use_mtls_endpoint) -> str: """Return the API endpoint used by the client. Args: @@ -460,7 +464,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1241,7 +1245,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1267,6 +1271,8 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.ListOperationsRequest(**request) @@ -1297,7 +1303,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1323,6 +1329,8 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.GetOperationRequest(**request) @@ -1353,7 +1361,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1382,6 +1390,8 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.CancelOperationRequest(**request) diff --git a/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/metrics_service_v2/transports/grpc.py b/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/metrics_service_v2/transports/grpc.py index d2c41d01e8..37b7ca97be 100755 --- a/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/metrics_service_v2/transports/grpc.py +++ b/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/metrics_service_v2/transports/grpc.py @@ -54,7 +54,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -85,7 +85,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, diff --git a/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/metrics_service_v2/transports/grpc_asyncio.py b/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/metrics_service_v2/transports/grpc_asyncio.py index 15b1ab3ad8..a9344009ed 100755 --- a/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/metrics_service_v2/transports/grpc_asyncio.py +++ b/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/metrics_service_v2/transports/grpc_asyncio.py @@ -58,7 +58,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -89,7 +89,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, diff --git a/tests/integration/goldens/logging_internal/noxfile.py b/tests/integration/goldens/logging_internal/noxfile.py index 778cbcbd60..5d3bca7cdc 100755 --- a/tests/integration/goldens/logging_internal/noxfile.py +++ b/tests/integration/goldens/logging_internal/noxfile.py @@ -107,6 +107,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) diff --git a/tests/integration/goldens/logging_internal/tests/unit/gapic/logging_v2/test_config_service_v2.py b/tests/integration/goldens/logging_internal/tests/unit/gapic/logging_v2/test_config_service_v2.py index ca28dea89c..639b54e163 100755 --- a/tests/integration/goldens/logging_internal/tests/unit/gapic/logging_v2/test_config_service_v2.py +++ b/tests/integration/goldens/logging_internal/tests/unit/gapic/logging_v2/test_config_service_v2.py @@ -105,6 +105,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert BaseConfigServiceV2Client._get_default_mtls_endpoint(None) is None assert BaseConfigServiceV2Client._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -112,6 +113,7 @@ def test__get_default_mtls_endpoint(): assert BaseConfigServiceV2Client._get_default_mtls_endpoint(sandbox_endpoint) == sandbox_mtls_endpoint assert BaseConfigServiceV2Client._get_default_mtls_endpoint(sandbox_mtls_endpoint) == sandbox_mtls_endpoint assert BaseConfigServiceV2Client._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert BaseConfigServiceV2Client._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): assert BaseConfigServiceV2Client._read_environment_variables() == (False, "auto", None) @@ -13580,6 +13582,37 @@ async def test_cancel_operation_from_dict_async(): ) call.assert_called() +def test_cancel_operation_flattened(): + client = BaseConfigServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = BaseConfigServiceV2AsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + None + ) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + def test_get_operation(transport: str = "grpc"): client = BaseConfigServiceV2Client( @@ -13709,6 +13742,37 @@ async def test_get_operation_from_dict_async(): ) call.assert_called() +def test_get_operation_flattened(): + client = BaseConfigServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = BaseConfigServiceV2AsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + def test_list_operations(transport: str = "grpc"): client = BaseConfigServiceV2Client( @@ -13838,6 +13902,37 @@ async def test_list_operations_from_dict_async(): ) call.assert_called() +def test_list_operations_flattened(): + client = BaseConfigServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = BaseConfigServiceV2AsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + def test_transport_close_grpc(): client = BaseConfigServiceV2Client( diff --git a/tests/integration/goldens/logging_internal/tests/unit/gapic/logging_v2/test_logging_service_v2.py b/tests/integration/goldens/logging_internal/tests/unit/gapic/logging_v2/test_logging_service_v2.py index 614126cfdb..8963383ef4 100755 --- a/tests/integration/goldens/logging_internal/tests/unit/gapic/logging_v2/test_logging_service_v2.py +++ b/tests/integration/goldens/logging_internal/tests/unit/gapic/logging_v2/test_logging_service_v2.py @@ -106,6 +106,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert LoggingServiceV2Client._get_default_mtls_endpoint(None) is None assert LoggingServiceV2Client._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -113,6 +114,7 @@ def test__get_default_mtls_endpoint(): assert LoggingServiceV2Client._get_default_mtls_endpoint(sandbox_endpoint) == sandbox_mtls_endpoint assert LoggingServiceV2Client._get_default_mtls_endpoint(sandbox_mtls_endpoint) == sandbox_mtls_endpoint assert LoggingServiceV2Client._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert LoggingServiceV2Client._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): assert LoggingServiceV2Client._read_environment_variables() == (False, "auto", None) @@ -3974,6 +3976,37 @@ async def test_cancel_operation_from_dict_async(): ) call.assert_called() +def test_cancel_operation_flattened(): + client = LoggingServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = LoggingServiceV2AsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + None + ) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + def test_get_operation(transport: str = "grpc"): client = LoggingServiceV2Client( @@ -4103,6 +4136,37 @@ async def test_get_operation_from_dict_async(): ) call.assert_called() +def test_get_operation_flattened(): + client = LoggingServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = LoggingServiceV2AsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + def test_list_operations(transport: str = "grpc"): client = LoggingServiceV2Client( @@ -4232,6 +4296,37 @@ async def test_list_operations_from_dict_async(): ) call.assert_called() +def test_list_operations_flattened(): + client = LoggingServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = LoggingServiceV2AsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + def test_transport_close_grpc(): client = LoggingServiceV2Client( diff --git a/tests/integration/goldens/logging_internal/tests/unit/gapic/logging_v2/test_metrics_service_v2.py b/tests/integration/goldens/logging_internal/tests/unit/gapic/logging_v2/test_metrics_service_v2.py index d843efe3c1..ab32958b3f 100755 --- a/tests/integration/goldens/logging_internal/tests/unit/gapic/logging_v2/test_metrics_service_v2.py +++ b/tests/integration/goldens/logging_internal/tests/unit/gapic/logging_v2/test_metrics_service_v2.py @@ -104,6 +104,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert BaseMetricsServiceV2Client._get_default_mtls_endpoint(None) is None assert BaseMetricsServiceV2Client._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -111,6 +112,7 @@ def test__get_default_mtls_endpoint(): assert BaseMetricsServiceV2Client._get_default_mtls_endpoint(sandbox_endpoint) == sandbox_mtls_endpoint assert BaseMetricsServiceV2Client._get_default_mtls_endpoint(sandbox_mtls_endpoint) == sandbox_mtls_endpoint assert BaseMetricsServiceV2Client._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert BaseMetricsServiceV2Client._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): assert BaseMetricsServiceV2Client._read_environment_variables() == (False, "auto", None) @@ -3778,6 +3780,37 @@ async def test_cancel_operation_from_dict_async(): ) call.assert_called() +def test_cancel_operation_flattened(): + client = BaseMetricsServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = BaseMetricsServiceV2AsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + None + ) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + def test_get_operation(transport: str = "grpc"): client = BaseMetricsServiceV2Client( @@ -3907,6 +3940,37 @@ async def test_get_operation_from_dict_async(): ) call.assert_called() +def test_get_operation_flattened(): + client = BaseMetricsServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = BaseMetricsServiceV2AsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + def test_list_operations(transport: str = "grpc"): client = BaseMetricsServiceV2Client( @@ -4036,6 +4100,37 @@ async def test_list_operations_from_dict_async(): ) call.assert_called() +def test_list_operations_flattened(): + client = BaseMetricsServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = BaseMetricsServiceV2AsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + def test_transport_close_grpc(): client = BaseMetricsServiceV2Client( diff --git a/tests/integration/goldens/redis_selective/google/cloud/redis_v1/services/cloud_redis/async_client.py b/tests/integration/goldens/redis_selective/google/cloud/redis_v1/services/cloud_redis/async_client.py index 6e826449ce..4ada4daa32 100755 --- a/tests/integration/goldens/redis_selective/google/cloud/redis_v1/services/cloud_redis/async_client.py +++ b/tests/integration/goldens/redis_selective/google/cloud/redis_v1/services/cloud_redis/async_client.py @@ -178,7 +178,7 @@ def transport(self) -> CloudRedisTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -964,7 +964,7 @@ async def sample_delete_instance(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -990,6 +990,8 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.ListOperationsRequest(**request) @@ -1016,7 +1018,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1042,6 +1044,8 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.GetOperationRequest(**request) @@ -1068,7 +1072,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1098,6 +1102,8 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.DeleteOperationRequest(**request) @@ -1120,7 +1126,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1149,6 +1155,8 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.CancelOperationRequest(**request) @@ -1171,7 +1179,7 @@ async def cancel_operation( async def wait_operation( self, - request: Optional[operations_pb2.WaitOperationRequest] = None, + request: Optional[Union[operations_pb2.WaitOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1203,6 +1211,8 @@ async def wait_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.WaitOperationRequest(**request) @@ -1229,7 +1239,7 @@ async def wait_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1255,6 +1265,8 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = locations_pb2.GetLocationRequest(**request) @@ -1281,7 +1293,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1307,6 +1319,8 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = locations_pb2.ListLocationsRequest(**request) diff --git a/tests/integration/goldens/redis_selective/google/cloud/redis_v1/services/cloud_redis/client.py b/tests/integration/goldens/redis_selective/google/cloud/redis_v1/services/cloud_redis/client.py index 32c43e15f1..2ec0f8709e 100755 --- a/tests/integration/goldens/redis_selective/google/cloud/redis_v1/services/cloud_redis/client.py +++ b/tests/integration/goldens/redis_selective/google/cloud/redis_v1/services/cloud_redis/client.py @@ -131,7 +131,7 @@ class CloudRedisClient(metaclass=CloudRedisClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -139,7 +139,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -149,6 +149,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # could not parse api_endpoint; return as-is + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -410,7 +414,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): return client_cert_source @staticmethod - def _get_api_endpoint(api_override, client_cert_source, universe_domain, use_mtls_endpoint): + def _get_api_endpoint(api_override, client_cert_source, universe_domain, use_mtls_endpoint) -> str: """Return the API endpoint used by the client. Args: @@ -496,7 +500,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1375,7 +1379,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1401,6 +1405,8 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.ListOperationsRequest(**request) @@ -1431,7 +1437,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1457,6 +1463,8 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.GetOperationRequest(**request) @@ -1487,7 +1495,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1517,6 +1525,8 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.DeleteOperationRequest(**request) @@ -1539,7 +1549,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1568,6 +1578,8 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.CancelOperationRequest(**request) @@ -1590,7 +1602,7 @@ def cancel_operation( def wait_operation( self, - request: Optional[operations_pb2.WaitOperationRequest] = None, + request: Optional[Union[operations_pb2.WaitOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1622,6 +1634,8 @@ def wait_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.WaitOperationRequest(**request) @@ -1652,7 +1666,7 @@ def wait_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1678,6 +1692,8 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = locations_pb2.GetLocationRequest(**request) @@ -1708,7 +1724,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1734,6 +1750,8 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = locations_pb2.ListLocationsRequest(**request) diff --git a/tests/integration/goldens/redis_selective/google/cloud/redis_v1/services/cloud_redis/transports/grpc.py b/tests/integration/goldens/redis_selective/google/cloud/redis_v1/services/cloud_redis/transports/grpc.py index fe65a8baf8..3e9ec3b573 100755 --- a/tests/integration/goldens/redis_selective/google/cloud/redis_v1/services/cloud_redis/transports/grpc.py +++ b/tests/integration/goldens/redis_selective/google/cloud/redis_v1/services/cloud_redis/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -86,7 +86,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, diff --git a/tests/integration/goldens/redis_selective/google/cloud/redis_v1/services/cloud_redis/transports/grpc_asyncio.py b/tests/integration/goldens/redis_selective/google/cloud/redis_v1/services/cloud_redis/transports/grpc_asyncio.py index a3393990f2..de6f824f30 100755 --- a/tests/integration/goldens/redis_selective/google/cloud/redis_v1/services/cloud_redis/transports/grpc_asyncio.py +++ b/tests/integration/goldens/redis_selective/google/cloud/redis_v1/services/cloud_redis/transports/grpc_asyncio.py @@ -59,7 +59,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, diff --git a/tests/integration/goldens/redis_selective/noxfile.py b/tests/integration/goldens/redis_selective/noxfile.py index d2fcf30488..2b6cbd1280 100755 --- a/tests/integration/goldens/redis_selective/noxfile.py +++ b/tests/integration/goldens/redis_selective/noxfile.py @@ -107,6 +107,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) diff --git a/tests/integration/goldens/redis_selective/tests/unit/gapic/redis_v1/test_cloud_redis.py b/tests/integration/goldens/redis_selective/tests/unit/gapic/redis_v1/test_cloud_redis.py index 44403c6627..1b85188c8a 100755 --- a/tests/integration/goldens/redis_selective/tests/unit/gapic/redis_v1/test_cloud_redis.py +++ b/tests/integration/goldens/redis_selective/tests/unit/gapic/redis_v1/test_cloud_redis.py @@ -122,6 +122,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert CloudRedisClient._get_default_mtls_endpoint(None) is None assert CloudRedisClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -129,6 +130,7 @@ def test__get_default_mtls_endpoint(): assert CloudRedisClient._get_default_mtls_endpoint(sandbox_endpoint) == sandbox_mtls_endpoint assert CloudRedisClient._get_default_mtls_endpoint(sandbox_mtls_endpoint) == sandbox_mtls_endpoint assert CloudRedisClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert CloudRedisClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): assert CloudRedisClient._read_environment_variables() == (False, "auto", None) @@ -7388,6 +7390,37 @@ async def test_delete_operation_from_dict_async(): ) call.assert_called() +def test_delete_operation_flattened(): + client = CloudRedisClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = CloudRedisAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + None + ) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + def test_cancel_operation(transport: str = "grpc"): client = CloudRedisClient( @@ -7517,6 +7550,37 @@ async def test_cancel_operation_from_dict_async(): ) call.assert_called() +def test_cancel_operation_flattened(): + client = CloudRedisClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = CloudRedisAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + None + ) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + def test_wait_operation(transport: str = "grpc"): client = CloudRedisClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -7645,6 +7709,37 @@ async def test_wait_operation_from_dict_async(): ) call.assert_called() +def test_wait_operation_flattened(): + client = CloudRedisClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.wait_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.WaitOperationRequest() +@pytest.mark.asyncio +async def test_wait_operation_flattened_async(): + client = CloudRedisAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.wait_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.WaitOperationRequest() + def test_get_operation(transport: str = "grpc"): client = CloudRedisClient( @@ -7774,6 +7869,37 @@ async def test_get_operation_from_dict_async(): ) call.assert_called() +def test_get_operation_flattened(): + client = CloudRedisClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = CloudRedisAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + def test_list_operations(transport: str = "grpc"): client = CloudRedisClient( @@ -7903,6 +8029,37 @@ async def test_list_operations_from_dict_async(): ) call.assert_called() +def test_list_operations_flattened(): + client = CloudRedisClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = CloudRedisAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + def test_list_locations(transport: str = "grpc"): client = CloudRedisClient( @@ -8032,6 +8189,37 @@ async def test_list_locations_from_dict_async(): ) call.assert_called() +def test_list_locations_flattened(): + client = CloudRedisClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = CloudRedisAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + def test_get_location(transport: str = "grpc"): client = CloudRedisClient( @@ -8160,6 +8348,37 @@ async def test_get_location_from_dict_async(): ) call.assert_called() +def test_get_location_flattened(): + client = CloudRedisClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = CloudRedisAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + def test_transport_close_grpc(): client = CloudRedisClient( From 3920092cdade32bb623caad8e17be015ec67dd9c Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Tue, 20 Jan 2026 19:33:46 -0800 Subject: [PATCH 20/26] improved typing --- .../%sub/services/%service/_mixins.py.j2 | 118 ++++++++++------- .../%sub/services/%service/client.py.j2 | 36 +++--- .../services/%service/_async_mixins.py.j2 | 120 ++++++++++-------- .../%sub/services/%service/_mixins.py.j2 | 120 ++++++++++-------- .../%sub/services/%service/async_client.py.j2 | 36 +++--- .../%sub/services/%service/client.py.j2 | 36 +++--- .../asset_v1/services/asset_service/client.py | 12 +- 7 files changed, 279 insertions(+), 199 deletions(-) diff --git a/gapic/ads-templates/%namespace/%name/%version/%sub/services/%service/_mixins.py.j2 b/gapic/ads-templates/%namespace/%name/%version/%sub/services/%service/_mixins.py.j2 index a76224af83..eb19c3c8bd 100644 --- a/gapic/ads-templates/%namespace/%name/%version/%sub/services/%service/_mixins.py.j2 +++ b/gapic/ads-templates/%namespace/%name/%version/%sub/services/%service/_mixins.py.j2 @@ -28,9 +28,11 @@ # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -40,12 +42,12 @@ # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Send the request. response = rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -80,9 +82,11 @@ # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -92,12 +96,12 @@ # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Send the request. response = rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -135,9 +139,11 @@ # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -147,11 +153,11 @@ # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Send the request. - rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + rpc(request_pb, retry=retry, timeout=timeout, metadata=metadata,) {% endif %} {% if "CancelOperation" in api.mixin_api_methods %} @@ -185,9 +191,11 @@ # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -197,11 +205,11 @@ # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Send the request. - rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + rpc(request_pb, retry=retry, timeout=timeout, metadata=metadata,) {% endif %} {% if "WaitOperation" in api.mixin_api_methods %} @@ -238,9 +246,11 @@ # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.WaitOperationRequest(**request) + request_pb = operations_pb2.WaitOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.WaitOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -250,7 +260,7 @@ # Send the request. response = rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -355,9 +365,11 @@ # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -367,12 +379,12 @@ # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("resource", request.resource),)), + (("resource", request_pb.resource),)), ) # Send the request. response = rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -473,9 +485,11 @@ # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -485,12 +499,12 @@ # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("resource", request.resource),)), + (("resource", request_pb.resource),)), ) # Send the request. response = rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -529,9 +543,11 @@ # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -541,12 +557,12 @@ # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("resource", request.resource),)), + (("resource", request_pb.resource),)), ) # Send the request. response = rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -584,9 +600,11 @@ # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -596,12 +614,12 @@ # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Send the request. response = rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -635,9 +653,11 @@ # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -647,12 +667,12 @@ # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Send the request. response = rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response diff --git a/gapic/ads-templates/%namespace/%name/%version/%sub/services/%service/client.py.j2 b/gapic/ads-templates/%namespace/%name/%version/%sub/services/%service/client.py.j2 index 29f1d5721c..445d51935c 100644 --- a/gapic/ads-templates/%namespace/%name/%version/%sub/services/%service/client.py.j2 +++ b/gapic/ads-templates/%namespace/%name/%version/%sub/services/%service/client.py.j2 @@ -634,9 +634,11 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta): # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -650,12 +652,12 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta): # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("resource", request.resource),)), + (("resource", request_pb.resource),)), ) # Send the request. response = rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -753,9 +755,11 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta): # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -769,12 +773,12 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta): # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("resource", request.resource),)), + (("resource", request_pb.resource),)), ) # Send the request. response = rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -811,9 +815,11 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta): # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -827,12 +833,12 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta): # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("resource", request.resource),)), + (("resource", request_pb.resource),)), ) # Send the request. response = rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response diff --git a/gapic/templates/%namespace/%name_%version/%sub/services/%service/_async_mixins.py.j2 b/gapic/templates/%namespace/%name_%version/%sub/services/%service/_async_mixins.py.j2 index 7b244b67c0..9f5ba3369b 100644 --- a/gapic/templates/%namespace/%name_%version/%sub/services/%service/_async_mixins.py.j2 +++ b/gapic/templates/%namespace/%name_%version/%sub/services/%service/_async_mixins.py.j2 @@ -29,9 +29,11 @@ # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -41,7 +43,7 @@ # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. @@ -49,7 +51,7 @@ # Send the request. response = await rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -83,9 +85,11 @@ # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -95,7 +99,7 @@ # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. @@ -103,7 +107,7 @@ # Send the request. response = await rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -140,9 +144,11 @@ # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -152,14 +158,14 @@ # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. self._client._validate_universe_domain() # Send the request. - await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + await rpc(request_pb, retry=retry, timeout=timeout, metadata=metadata,) {% endif %} {% if "CancelOperation" in api.mixin_api_methods %} @@ -192,9 +198,11 @@ # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -204,14 +212,14 @@ # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. self._client._validate_universe_domain() # Send the request. - await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + await rpc(request_pb, retry=retry, timeout=timeout, metadata=metadata,) {% endif %} {% if "WaitOperation" in api.mixin_api_methods %} @@ -247,9 +255,11 @@ # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.WaitOperationRequest(**request) + request_pb = operations_pb2.WaitOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.WaitOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -259,7 +269,7 @@ # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. @@ -267,7 +277,7 @@ # Send the request. response = await rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -371,9 +381,11 @@ # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -383,7 +395,7 @@ # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("resource", request.resource),)), + (("resource", request_pb.resource),)), ) # Validate the universe domain. @@ -391,7 +403,7 @@ # Send the request. response = await rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -491,9 +503,11 @@ # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -503,7 +517,7 @@ # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("resource", request.resource),)), + (("resource", request_pb.resource),)), ) # Validate the universe domain. @@ -511,7 +525,7 @@ # Send the request. response = await rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -549,9 +563,11 @@ # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -561,7 +577,7 @@ # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("resource", request.resource),)), + (("resource", request_pb.resource),)), ) # Validate the universe domain. @@ -569,7 +585,7 @@ # Send the request. response = await rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -606,9 +622,11 @@ # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -618,7 +636,7 @@ # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. @@ -626,7 +644,7 @@ # Send the request. response = await rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -659,9 +677,11 @@ # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -671,7 +691,7 @@ # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. @@ -679,7 +699,7 @@ # Send the request. response = await rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response diff --git a/gapic/templates/%namespace/%name_%version/%sub/services/%service/_mixins.py.j2 b/gapic/templates/%namespace/%name_%version/%sub/services/%service/_mixins.py.j2 index 1876a630dd..4d02f0d91e 100644 --- a/gapic/templates/%namespace/%name_%version/%sub/services/%service/_mixins.py.j2 +++ b/gapic/templates/%namespace/%name_%version/%sub/services/%service/_mixins.py.j2 @@ -27,9 +27,11 @@ # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -39,7 +41,7 @@ # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. @@ -48,7 +50,7 @@ try: # Send the request. response = rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -85,9 +87,11 @@ # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -97,7 +101,7 @@ # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. @@ -106,7 +110,7 @@ try: # Send the request. response = rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -146,9 +150,11 @@ # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -158,14 +164,14 @@ # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. self._validate_universe_domain() # Send the request. - rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + rpc(request_pb, retry=retry, timeout=timeout, metadata=metadata,) {% endif %} {% if "CancelOperation" in api.mixin_api_methods %} @@ -198,9 +204,11 @@ # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -210,14 +218,14 @@ # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. self._validate_universe_domain() # Send the request. - rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + rpc(request_pb, retry=retry, timeout=timeout, metadata=metadata,) {% endif %} {% if "WaitOperation" in api.mixin_api_methods %} @@ -253,9 +261,11 @@ # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.WaitOperationRequest(**request) + request_pb = operations_pb2.WaitOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.WaitOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -265,7 +275,7 @@ # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. @@ -274,7 +284,7 @@ try: # Send the request. response = rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -381,9 +391,11 @@ # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -393,7 +405,7 @@ # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("resource", request.resource),)), + (("resource", request_pb.resource),)), ) # Validate the universe domain. @@ -402,7 +414,7 @@ try: # Send the request. response = rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -505,9 +517,11 @@ # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -517,7 +531,7 @@ # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("resource", request.resource),)), + (("resource", request_pb.resource),)), ) # Validate the universe domain. @@ -526,7 +540,7 @@ try: # Send the request. response = rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -567,9 +581,11 @@ # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -579,7 +595,7 @@ # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("resource", request.resource),)), + (("resource", request_pb.resource),)), ) # Validate the universe domain. @@ -588,7 +604,7 @@ try: # Send the request. response = rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -628,9 +644,11 @@ # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -640,7 +658,7 @@ # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. @@ -649,7 +667,7 @@ try: # Send the request. response = rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -685,9 +703,11 @@ # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -697,7 +717,7 @@ # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. @@ -706,7 +726,7 @@ try: # Send the request. response = rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response diff --git a/gapic/templates/%namespace/%name_%version/%sub/services/%service/async_client.py.j2 b/gapic/templates/%namespace/%name_%version/%sub/services/%service/async_client.py.j2 index e3752a8a55..6f712b3b2e 100644 --- a/gapic/templates/%namespace/%name_%version/%sub/services/%service/async_client.py.j2 +++ b/gapic/templates/%namespace/%name_%version/%sub/services/%service/async_client.py.j2 @@ -531,9 +531,11 @@ class {{ service.async_client_name }}: # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -542,14 +544,14 @@ class {{ service.async_client_name }}: # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata((("resource", request_pb.resource),)), ) # Validate the universe domain. self._client._validate_universe_domain() # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc(request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -647,9 +649,11 @@ class {{ service.async_client_name }}: # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -658,14 +662,14 @@ class {{ service.async_client_name }}: # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata((("resource", request_pb.resource),)), ) # Validate the universe domain. self._client._validate_universe_domain() # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc(request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -701,9 +705,11 @@ class {{ service.async_client_name }}: # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -712,14 +718,14 @@ class {{ service.async_client_name }}: # Certain fields should be provided within the metadata header; # add these here. metadata = tuple(metadata) + ( - gapic_v1.routing_header.to_grpc_metadata((("resource", request.resource),)), + gapic_v1.routing_header.to_grpc_metadata((("resource", request_pb.resource),)), ) # Validate the universe domain. self._client._validate_universe_domain() # Send the request. - response = await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + response = await rpc(request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response diff --git a/gapic/templates/%namespace/%name_%version/%sub/services/%service/client.py.j2 b/gapic/templates/%namespace/%name_%version/%sub/services/%service/client.py.j2 index 9a22c55ece..301f9d5347 100644 --- a/gapic/templates/%namespace/%name_%version/%sub/services/%service/client.py.j2 +++ b/gapic/templates/%namespace/%name_%version/%sub/services/%service/client.py.j2 @@ -798,9 +798,11 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta): # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -814,7 +816,7 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta): # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("resource", request.resource),)), + (("resource", request_pb.resource),)), ) # Validate the universe domain. @@ -823,7 +825,7 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta): try: # Send the request. response = rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -924,9 +926,11 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta): # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -940,7 +944,7 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta): # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("resource", request.resource),)), + (("resource", request_pb.resource),)), ) # Validate the universe domain. @@ -949,7 +953,7 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta): try: # Send the request. response = rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -988,9 +992,11 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta): # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1004,7 +1010,7 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta): # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("resource", request.resource),)), + (("resource", request_pb.resource),)), ) # Validate the universe domain. @@ -1013,7 +1019,7 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta): try: # Send the request. response = rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response diff --git a/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/client.py b/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/client.py index b771d004be..15f093bdba 100755 --- a/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/client.py +++ b/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/client.py @@ -3607,9 +3607,11 @@ def get_operation( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3619,7 +3621,7 @@ def get_operation( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. @@ -3628,7 +3630,7 @@ def get_operation( try: # Send the request. response = rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response From 681e6268467eb50aced9f584a7b082b18a9a49d0 Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Tue, 20 Jan 2026 19:34:43 -0800 Subject: [PATCH 21/26] updated more goldens --- .../services/eventarc/async_client.py | 38 ++- .../eventarc_v1/services/eventarc/client.py | 48 ++- .../services/eventarc/transports/grpc.py | 4 +- .../eventarc/transports/grpc_asyncio.py | 4 +- tests/integration/goldens/eventarc/noxfile.py | 2 + .../unit/gapic/eventarc_v1/test_eventarc.py | 299 ++++++++++++++++++ .../config_service_v2/async_client.py | 14 +- .../services/config_service_v2/client.py | 24 +- .../config_service_v2/transports/grpc.py | 4 +- .../transports/grpc_asyncio.py | 4 +- .../logging_service_v2/async_client.py | 14 +- .../services/logging_service_v2/client.py | 24 +- .../logging_service_v2/transports/grpc.py | 4 +- .../transports/grpc_asyncio.py | 4 +- .../metrics_service_v2/async_client.py | 14 +- .../services/metrics_service_v2/client.py | 24 +- .../metrics_service_v2/transports/grpc.py | 4 +- .../transports/grpc_asyncio.py | 4 +- tests/integration/goldens/logging/noxfile.py | 2 + .../logging_v2/test_config_service_v2.py | 95 ++++++ .../logging_v2/test_logging_service_v2.py | 95 ++++++ .../logging_v2/test_metrics_service_v2.py | 95 ++++++ .../services/cloud_redis/async_client.py | 30 +- .../redis_v1/services/cloud_redis/client.py | 40 ++- .../services/cloud_redis/transports/grpc.py | 4 +- .../cloud_redis/transports/grpc_asyncio.py | 4 +- tests/integration/goldens/redis/noxfile.py | 2 + .../unit/gapic/redis_v1/test_cloud_redis.py | 219 +++++++++++++ 28 files changed, 1024 insertions(+), 95 deletions(-) diff --git a/tests/integration/goldens/eventarc/google/cloud/eventarc_v1/services/eventarc/async_client.py b/tests/integration/goldens/eventarc/google/cloud/eventarc_v1/services/eventarc/async_client.py index 09b53be781..e20efdef99 100755 --- a/tests/integration/goldens/eventarc/google/cloud/eventarc_v1/services/eventarc/async_client.py +++ b/tests/integration/goldens/eventarc/google/cloud/eventarc_v1/services/eventarc/async_client.py @@ -188,7 +188,7 @@ def transport(self) -> EventarcTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -2550,7 +2550,7 @@ async def sample_update_google_channel_config(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2576,6 +2576,8 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.ListOperationsRequest(**request) @@ -2602,7 +2604,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2628,6 +2630,8 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.GetOperationRequest(**request) @@ -2654,7 +2658,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2684,6 +2688,8 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.DeleteOperationRequest(**request) @@ -2706,7 +2712,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2735,6 +2741,8 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.CancelOperationRequest(**request) @@ -2757,7 +2765,7 @@ async def cancel_operation( async def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2849,6 +2857,8 @@ async def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = iam_policy_pb2.SetIamPolicyRequest(**request) @@ -2875,7 +2885,7 @@ async def set_iam_policy( async def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2968,6 +2978,8 @@ async def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = iam_policy_pb2.GetIamPolicyRequest(**request) @@ -2994,7 +3006,7 @@ async def get_iam_policy( async def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3025,6 +3037,8 @@ async def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = iam_policy_pb2.TestIamPermissionsRequest(**request) @@ -3051,7 +3065,7 @@ async def test_iam_permissions( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3077,6 +3091,8 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = locations_pb2.GetLocationRequest(**request) @@ -3103,7 +3119,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3129,6 +3145,8 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = locations_pb2.ListLocationsRequest(**request) diff --git a/tests/integration/goldens/eventarc/google/cloud/eventarc_v1/services/eventarc/client.py b/tests/integration/goldens/eventarc/google/cloud/eventarc_v1/services/eventarc/client.py index 3accde24c6..e804c0f879 100755 --- a/tests/integration/goldens/eventarc/google/cloud/eventarc_v1/services/eventarc/client.py +++ b/tests/integration/goldens/eventarc/google/cloud/eventarc_v1/services/eventarc/client.py @@ -113,7 +113,7 @@ class EventarcClient(metaclass=EventarcClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -121,7 +121,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -131,6 +131,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # could not parse api_endpoint; return as-is + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -491,7 +495,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): return client_cert_source @staticmethod - def _get_api_endpoint(api_override, client_cert_source, universe_domain, use_mtls_endpoint): + def _get_api_endpoint(api_override, client_cert_source, universe_domain, use_mtls_endpoint) -> str: """Return the API endpoint used by the client. Args: @@ -577,7 +581,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -2997,7 +3001,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3023,6 +3027,8 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.ListOperationsRequest(**request) @@ -3053,7 +3059,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3079,6 +3085,8 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.GetOperationRequest(**request) @@ -3109,7 +3117,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3139,6 +3147,8 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.DeleteOperationRequest(**request) @@ -3161,7 +3171,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3190,6 +3200,8 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.CancelOperationRequest(**request) @@ -3212,7 +3224,7 @@ def cancel_operation( def set_iam_policy( self, - request: Optional[iam_policy_pb2.SetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.SetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3304,6 +3316,8 @@ def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = iam_policy_pb2.SetIamPolicyRequest(**request) @@ -3334,7 +3348,7 @@ def set_iam_policy( def get_iam_policy( self, - request: Optional[iam_policy_pb2.GetIamPolicyRequest] = None, + request: Optional[Union[iam_policy_pb2.GetIamPolicyRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3427,6 +3441,8 @@ def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = iam_policy_pb2.GetIamPolicyRequest(**request) @@ -3457,7 +3473,7 @@ def get_iam_policy( def test_iam_permissions( self, - request: Optional[iam_policy_pb2.TestIamPermissionsRequest] = None, + request: Optional[Union[iam_policy_pb2.TestIamPermissionsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3488,6 +3504,8 @@ def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = iam_policy_pb2.TestIamPermissionsRequest(**request) @@ -3518,7 +3536,7 @@ def test_iam_permissions( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3544,6 +3562,8 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = locations_pb2.GetLocationRequest(**request) @@ -3574,7 +3594,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3600,6 +3620,8 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = locations_pb2.ListLocationsRequest(**request) diff --git a/tests/integration/goldens/eventarc/google/cloud/eventarc_v1/services/eventarc/transports/grpc.py b/tests/integration/goldens/eventarc/google/cloud/eventarc_v1/services/eventarc/transports/grpc.py index 887700548d..3f7d58767e 100755 --- a/tests/integration/goldens/eventarc/google/cloud/eventarc_v1/services/eventarc/transports/grpc.py +++ b/tests/integration/goldens/eventarc/google/cloud/eventarc_v1/services/eventarc/transports/grpc.py @@ -63,7 +63,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -94,7 +94,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, diff --git a/tests/integration/goldens/eventarc/google/cloud/eventarc_v1/services/eventarc/transports/grpc_asyncio.py b/tests/integration/goldens/eventarc/google/cloud/eventarc_v1/services/eventarc/transports/grpc_asyncio.py index 6c940b3a82..c9c3af6c4f 100755 --- a/tests/integration/goldens/eventarc/google/cloud/eventarc_v1/services/eventarc/transports/grpc_asyncio.py +++ b/tests/integration/goldens/eventarc/google/cloud/eventarc_v1/services/eventarc/transports/grpc_asyncio.py @@ -67,7 +67,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -98,7 +98,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, diff --git a/tests/integration/goldens/eventarc/noxfile.py b/tests/integration/goldens/eventarc/noxfile.py index 3f123b8d36..f4bde8fe92 100755 --- a/tests/integration/goldens/eventarc/noxfile.py +++ b/tests/integration/goldens/eventarc/noxfile.py @@ -107,6 +107,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) diff --git a/tests/integration/goldens/eventarc/tests/unit/gapic/eventarc_v1/test_eventarc.py b/tests/integration/goldens/eventarc/tests/unit/gapic/eventarc_v1/test_eventarc.py index 88e728b9ca..8ce71fced4 100755 --- a/tests/integration/goldens/eventarc/tests/unit/gapic/eventarc_v1/test_eventarc.py +++ b/tests/integration/goldens/eventarc/tests/unit/gapic/eventarc_v1/test_eventarc.py @@ -124,6 +124,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert EventarcClient._get_default_mtls_endpoint(None) is None assert EventarcClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -131,6 +132,7 @@ def test__get_default_mtls_endpoint(): assert EventarcClient._get_default_mtls_endpoint(sandbox_endpoint) == sandbox_mtls_endpoint assert EventarcClient._get_default_mtls_endpoint(sandbox_mtls_endpoint) == sandbox_mtls_endpoint assert EventarcClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert EventarcClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): assert EventarcClient._read_environment_variables() == (False, "auto", None) @@ -16124,6 +16126,37 @@ async def test_delete_operation_from_dict_async(): ) call.assert_called() +def test_delete_operation_flattened(): + client = EventarcClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = EventarcAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + None + ) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + def test_cancel_operation(transport: str = "grpc"): client = EventarcClient( @@ -16253,6 +16286,37 @@ async def test_cancel_operation_from_dict_async(): ) call.assert_called() +def test_cancel_operation_flattened(): + client = EventarcClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = EventarcAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + None + ) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + def test_get_operation(transport: str = "grpc"): client = EventarcClient( @@ -16382,6 +16446,37 @@ async def test_get_operation_from_dict_async(): ) call.assert_called() +def test_get_operation_flattened(): + client = EventarcClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = EventarcAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + def test_list_operations(transport: str = "grpc"): client = EventarcClient( @@ -16511,6 +16606,37 @@ async def test_list_operations_from_dict_async(): ) call.assert_called() +def test_list_operations_flattened(): + client = EventarcClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = EventarcAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + def test_list_locations(transport: str = "grpc"): client = EventarcClient( @@ -16640,6 +16766,37 @@ async def test_list_locations_from_dict_async(): ) call.assert_called() +def test_list_locations_flattened(): + client = EventarcClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = EventarcAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + def test_get_location(transport: str = "grpc"): client = EventarcClient( @@ -16768,6 +16925,37 @@ async def test_get_location_from_dict_async(): ) call.assert_called() +def test_get_location_flattened(): + client = EventarcClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = EventarcAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + def test_set_iam_policy(transport: str = "grpc"): client = EventarcClient( @@ -16914,6 +17102,43 @@ async def test_set_iam_policy_from_dict_async(): ) call.assert_called() + +def test_set_iam_policy_flattened(): + client = EventarcClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + + client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_set_iam_policy_flattened_async(): + client = EventarcAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.set_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy() + ) + + await client.set_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.SetIamPolicyRequest() + def test_get_iam_policy(transport: str = "grpc"): client = EventarcClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -17071,6 +17296,43 @@ async def test_get_iam_policy_from_dict_async(): ) call.assert_called() + +def test_get_iam_policy_flattened(): + client = EventarcClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = policy_pb2.Policy() + + client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + + +@pytest.mark.asyncio +async def test_get_iam_policy_flattened_async(): + client = EventarcAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_iam_policy), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + policy_pb2.Policy() + ) + + await client.get_iam_policy() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.GetIamPolicyRequest() + def test_test_iam_permissions(transport: str = "grpc"): client = EventarcClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -17237,6 +17499,43 @@ async def test_test_iam_permissions_from_dict_async(): call.assert_called() +def test_test_iam_permissions_flattened(): + client = EventarcClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.test_iam_permissions), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = iam_policy_pb2.TestIamPermissionsResponse() + + client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + +@pytest.mark.asyncio +async def test_test_iam_permissions_flattened_async(): + client = EventarcAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.test_iam_permissions), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + iam_policy_pb2.TestIamPermissionsResponse() + ) + + await client.test_iam_permissions() + + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == iam_policy_pb2.TestIamPermissionsRequest() + + def test_transport_close_grpc(): client = EventarcClient( credentials=ga_credentials.AnonymousCredentials(), diff --git a/tests/integration/goldens/logging/google/cloud/logging_v2/services/config_service_v2/async_client.py b/tests/integration/goldens/logging/google/cloud/logging_v2/services/config_service_v2/async_client.py index b5d7d26514..b3264d843e 100755 --- a/tests/integration/goldens/logging/google/cloud/logging_v2/services/config_service_v2/async_client.py +++ b/tests/integration/goldens/logging/google/cloud/logging_v2/services/config_service_v2/async_client.py @@ -168,7 +168,7 @@ def transport(self) -> ConfigServiceV2Transport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -3898,7 +3898,7 @@ async def sample_copy_log_entries(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3924,6 +3924,8 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.ListOperationsRequest(**request) @@ -3950,7 +3952,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -3976,6 +3978,8 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.GetOperationRequest(**request) @@ -4002,7 +4006,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4031,6 +4035,8 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.CancelOperationRequest(**request) diff --git a/tests/integration/goldens/logging/google/cloud/logging_v2/services/config_service_v2/client.py b/tests/integration/goldens/logging/google/cloud/logging_v2/services/config_service_v2/client.py index b2e701b095..0d13aee340 100755 --- a/tests/integration/goldens/logging/google/cloud/logging_v2/services/config_service_v2/client.py +++ b/tests/integration/goldens/logging/google/cloud/logging_v2/services/config_service_v2/client.py @@ -97,7 +97,7 @@ class ConfigServiceV2Client(metaclass=ConfigServiceV2ClientMeta): """Service for configuring sinks used to route log entries.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -105,7 +105,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -115,6 +115,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # could not parse api_endpoint; return as-is + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -442,7 +446,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): return client_cert_source @staticmethod - def _get_api_endpoint(api_override, client_cert_source, universe_domain, use_mtls_endpoint): + def _get_api_endpoint(api_override, client_cert_source, universe_domain, use_mtls_endpoint) -> str: """Return the API endpoint used by the client. Args: @@ -528,7 +532,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -4316,7 +4320,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4342,6 +4346,8 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.ListOperationsRequest(**request) @@ -4372,7 +4378,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4398,6 +4404,8 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.GetOperationRequest(**request) @@ -4428,7 +4436,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -4457,6 +4465,8 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.CancelOperationRequest(**request) diff --git a/tests/integration/goldens/logging/google/cloud/logging_v2/services/config_service_v2/transports/grpc.py b/tests/integration/goldens/logging/google/cloud/logging_v2/services/config_service_v2/transports/grpc.py index ac3a4393a8..8ad6eaad62 100755 --- a/tests/integration/goldens/logging/google/cloud/logging_v2/services/config_service_v2/transports/grpc.py +++ b/tests/integration/goldens/logging/google/cloud/logging_v2/services/config_service_v2/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -86,7 +86,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, diff --git a/tests/integration/goldens/logging/google/cloud/logging_v2/services/config_service_v2/transports/grpc_asyncio.py b/tests/integration/goldens/logging/google/cloud/logging_v2/services/config_service_v2/transports/grpc_asyncio.py index fc7af0c06b..7aacec1ecf 100755 --- a/tests/integration/goldens/logging/google/cloud/logging_v2/services/config_service_v2/transports/grpc_asyncio.py +++ b/tests/integration/goldens/logging/google/cloud/logging_v2/services/config_service_v2/transports/grpc_asyncio.py @@ -59,7 +59,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, diff --git a/tests/integration/goldens/logging/google/cloud/logging_v2/services/logging_service_v2/async_client.py b/tests/integration/goldens/logging/google/cloud/logging_v2/services/logging_service_v2/async_client.py index f84e9f6ec5..953c59eb4a 100755 --- a/tests/integration/goldens/logging/google/cloud/logging_v2/services/logging_service_v2/async_client.py +++ b/tests/integration/goldens/logging/google/cloud/logging_v2/services/logging_service_v2/async_client.py @@ -153,7 +153,7 @@ def transport(self) -> LoggingServiceV2Transport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1013,7 +1013,7 @@ def request_generator(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1039,6 +1039,8 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.ListOperationsRequest(**request) @@ -1065,7 +1067,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1091,6 +1093,8 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.GetOperationRequest(**request) @@ -1117,7 +1121,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1146,6 +1150,8 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.CancelOperationRequest(**request) diff --git a/tests/integration/goldens/logging/google/cloud/logging_v2/services/logging_service_v2/client.py b/tests/integration/goldens/logging/google/cloud/logging_v2/services/logging_service_v2/client.py index 8c37951cb5..3c2e5510eb 100755 --- a/tests/integration/goldens/logging/google/cloud/logging_v2/services/logging_service_v2/client.py +++ b/tests/integration/goldens/logging/google/cloud/logging_v2/services/logging_service_v2/client.py @@ -94,7 +94,7 @@ class LoggingServiceV2Client(metaclass=LoggingServiceV2ClientMeta): """Service for ingesting and querying logs.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -102,7 +102,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -112,6 +112,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # could not parse api_endpoint; return as-is + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -373,7 +377,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): return client_cert_source @staticmethod - def _get_api_endpoint(api_override, client_cert_source, universe_domain, use_mtls_endpoint): + def _get_api_endpoint(api_override, client_cert_source, universe_domain, use_mtls_endpoint) -> str: """Return the API endpoint used by the client. Args: @@ -459,7 +463,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1390,7 +1394,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1416,6 +1420,8 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.ListOperationsRequest(**request) @@ -1446,7 +1452,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1472,6 +1478,8 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.GetOperationRequest(**request) @@ -1502,7 +1510,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1531,6 +1539,8 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.CancelOperationRequest(**request) diff --git a/tests/integration/goldens/logging/google/cloud/logging_v2/services/logging_service_v2/transports/grpc.py b/tests/integration/goldens/logging/google/cloud/logging_v2/services/logging_service_v2/transports/grpc.py index 8edc617027..86a6f3711d 100755 --- a/tests/integration/goldens/logging/google/cloud/logging_v2/services/logging_service_v2/transports/grpc.py +++ b/tests/integration/goldens/logging/google/cloud/logging_v2/services/logging_service_v2/transports/grpc.py @@ -54,7 +54,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -85,7 +85,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, diff --git a/tests/integration/goldens/logging/google/cloud/logging_v2/services/logging_service_v2/transports/grpc_asyncio.py b/tests/integration/goldens/logging/google/cloud/logging_v2/services/logging_service_v2/transports/grpc_asyncio.py index 92aa1d5256..2dced8c696 100755 --- a/tests/integration/goldens/logging/google/cloud/logging_v2/services/logging_service_v2/transports/grpc_asyncio.py +++ b/tests/integration/goldens/logging/google/cloud/logging_v2/services/logging_service_v2/transports/grpc_asyncio.py @@ -58,7 +58,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -89,7 +89,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, diff --git a/tests/integration/goldens/logging/google/cloud/logging_v2/services/metrics_service_v2/async_client.py b/tests/integration/goldens/logging/google/cloud/logging_v2/services/metrics_service_v2/async_client.py index ad659243d7..81d65166a4 100755 --- a/tests/integration/goldens/logging/google/cloud/logging_v2/services/metrics_service_v2/async_client.py +++ b/tests/integration/goldens/logging/google/cloud/logging_v2/services/metrics_service_v2/async_client.py @@ -154,7 +154,7 @@ def transport(self) -> MetricsServiceV2Transport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -864,7 +864,7 @@ async def sample_delete_log_metric(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -890,6 +890,8 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.ListOperationsRequest(**request) @@ -916,7 +918,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -942,6 +944,8 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.GetOperationRequest(**request) @@ -968,7 +972,7 @@ async def get_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -997,6 +1001,8 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.CancelOperationRequest(**request) diff --git a/tests/integration/goldens/logging/google/cloud/logging_v2/services/metrics_service_v2/client.py b/tests/integration/goldens/logging/google/cloud/logging_v2/services/metrics_service_v2/client.py index 6ff3b7ac02..36b5118970 100755 --- a/tests/integration/goldens/logging/google/cloud/logging_v2/services/metrics_service_v2/client.py +++ b/tests/integration/goldens/logging/google/cloud/logging_v2/services/metrics_service_v2/client.py @@ -95,7 +95,7 @@ class MetricsServiceV2Client(metaclass=MetricsServiceV2ClientMeta): """Service for configuring logs-based metrics.""" @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -103,7 +103,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -113,6 +113,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # could not parse api_endpoint; return as-is + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -374,7 +378,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): return client_cert_source @staticmethod - def _get_api_endpoint(api_override, client_cert_source, universe_domain, use_mtls_endpoint): + def _get_api_endpoint(api_override, client_cert_source, universe_domain, use_mtls_endpoint) -> str: """Return the API endpoint used by the client. Args: @@ -460,7 +464,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1241,7 +1245,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1267,6 +1271,8 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.ListOperationsRequest(**request) @@ -1297,7 +1303,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1323,6 +1329,8 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.GetOperationRequest(**request) @@ -1353,7 +1361,7 @@ def get_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1382,6 +1390,8 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.CancelOperationRequest(**request) diff --git a/tests/integration/goldens/logging/google/cloud/logging_v2/services/metrics_service_v2/transports/grpc.py b/tests/integration/goldens/logging/google/cloud/logging_v2/services/metrics_service_v2/transports/grpc.py index d2c41d01e8..37b7ca97be 100755 --- a/tests/integration/goldens/logging/google/cloud/logging_v2/services/metrics_service_v2/transports/grpc.py +++ b/tests/integration/goldens/logging/google/cloud/logging_v2/services/metrics_service_v2/transports/grpc.py @@ -54,7 +54,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -85,7 +85,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, diff --git a/tests/integration/goldens/logging/google/cloud/logging_v2/services/metrics_service_v2/transports/grpc_asyncio.py b/tests/integration/goldens/logging/google/cloud/logging_v2/services/metrics_service_v2/transports/grpc_asyncio.py index 15b1ab3ad8..a9344009ed 100755 --- a/tests/integration/goldens/logging/google/cloud/logging_v2/services/metrics_service_v2/transports/grpc_asyncio.py +++ b/tests/integration/goldens/logging/google/cloud/logging_v2/services/metrics_service_v2/transports/grpc_asyncio.py @@ -58,7 +58,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -89,7 +89,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, diff --git a/tests/integration/goldens/logging/noxfile.py b/tests/integration/goldens/logging/noxfile.py index 778cbcbd60..5d3bca7cdc 100755 --- a/tests/integration/goldens/logging/noxfile.py +++ b/tests/integration/goldens/logging/noxfile.py @@ -107,6 +107,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) diff --git a/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_config_service_v2.py b/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_config_service_v2.py index 9df459055f..2c712a0713 100755 --- a/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_config_service_v2.py +++ b/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_config_service_v2.py @@ -105,6 +105,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert ConfigServiceV2Client._get_default_mtls_endpoint(None) is None assert ConfigServiceV2Client._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -112,6 +113,7 @@ def test__get_default_mtls_endpoint(): assert ConfigServiceV2Client._get_default_mtls_endpoint(sandbox_endpoint) == sandbox_mtls_endpoint assert ConfigServiceV2Client._get_default_mtls_endpoint(sandbox_mtls_endpoint) == sandbox_mtls_endpoint assert ConfigServiceV2Client._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert ConfigServiceV2Client._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): assert ConfigServiceV2Client._read_environment_variables() == (False, "auto", None) @@ -13580,6 +13582,37 @@ async def test_cancel_operation_from_dict_async(): ) call.assert_called() +def test_cancel_operation_flattened(): + client = ConfigServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = ConfigServiceV2AsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + None + ) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + def test_get_operation(transport: str = "grpc"): client = ConfigServiceV2Client( @@ -13709,6 +13742,37 @@ async def test_get_operation_from_dict_async(): ) call.assert_called() +def test_get_operation_flattened(): + client = ConfigServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = ConfigServiceV2AsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + def test_list_operations(transport: str = "grpc"): client = ConfigServiceV2Client( @@ -13838,6 +13902,37 @@ async def test_list_operations_from_dict_async(): ) call.assert_called() +def test_list_operations_flattened(): + client = ConfigServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = ConfigServiceV2AsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + def test_transport_close_grpc(): client = ConfigServiceV2Client( diff --git a/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_logging_service_v2.py b/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_logging_service_v2.py index 614126cfdb..8963383ef4 100755 --- a/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_logging_service_v2.py +++ b/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_logging_service_v2.py @@ -106,6 +106,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert LoggingServiceV2Client._get_default_mtls_endpoint(None) is None assert LoggingServiceV2Client._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -113,6 +114,7 @@ def test__get_default_mtls_endpoint(): assert LoggingServiceV2Client._get_default_mtls_endpoint(sandbox_endpoint) == sandbox_mtls_endpoint assert LoggingServiceV2Client._get_default_mtls_endpoint(sandbox_mtls_endpoint) == sandbox_mtls_endpoint assert LoggingServiceV2Client._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert LoggingServiceV2Client._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): assert LoggingServiceV2Client._read_environment_variables() == (False, "auto", None) @@ -3974,6 +3976,37 @@ async def test_cancel_operation_from_dict_async(): ) call.assert_called() +def test_cancel_operation_flattened(): + client = LoggingServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = LoggingServiceV2AsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + None + ) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + def test_get_operation(transport: str = "grpc"): client = LoggingServiceV2Client( @@ -4103,6 +4136,37 @@ async def test_get_operation_from_dict_async(): ) call.assert_called() +def test_get_operation_flattened(): + client = LoggingServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = LoggingServiceV2AsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + def test_list_operations(transport: str = "grpc"): client = LoggingServiceV2Client( @@ -4232,6 +4296,37 @@ async def test_list_operations_from_dict_async(): ) call.assert_called() +def test_list_operations_flattened(): + client = LoggingServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = LoggingServiceV2AsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + def test_transport_close_grpc(): client = LoggingServiceV2Client( diff --git a/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_metrics_service_v2.py b/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_metrics_service_v2.py index 027c8ab372..090121a22c 100755 --- a/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_metrics_service_v2.py +++ b/tests/integration/goldens/logging/tests/unit/gapic/logging_v2/test_metrics_service_v2.py @@ -104,6 +104,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert MetricsServiceV2Client._get_default_mtls_endpoint(None) is None assert MetricsServiceV2Client._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -111,6 +112,7 @@ def test__get_default_mtls_endpoint(): assert MetricsServiceV2Client._get_default_mtls_endpoint(sandbox_endpoint) == sandbox_mtls_endpoint assert MetricsServiceV2Client._get_default_mtls_endpoint(sandbox_mtls_endpoint) == sandbox_mtls_endpoint assert MetricsServiceV2Client._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert MetricsServiceV2Client._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): assert MetricsServiceV2Client._read_environment_variables() == (False, "auto", None) @@ -3778,6 +3780,37 @@ async def test_cancel_operation_from_dict_async(): ) call.assert_called() +def test_cancel_operation_flattened(): + client = MetricsServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = MetricsServiceV2AsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + None + ) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + def test_get_operation(transport: str = "grpc"): client = MetricsServiceV2Client( @@ -3907,6 +3940,37 @@ async def test_get_operation_from_dict_async(): ) call.assert_called() +def test_get_operation_flattened(): + client = MetricsServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = MetricsServiceV2AsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + def test_list_operations(transport: str = "grpc"): client = MetricsServiceV2Client( @@ -4036,6 +4100,37 @@ async def test_list_operations_from_dict_async(): ) call.assert_called() +def test_list_operations_flattened(): + client = MetricsServiceV2Client( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = MetricsServiceV2AsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + def test_transport_close_grpc(): client = MetricsServiceV2Client( diff --git a/tests/integration/goldens/redis/google/cloud/redis_v1/services/cloud_redis/async_client.py b/tests/integration/goldens/redis/google/cloud/redis_v1/services/cloud_redis/async_client.py index ea3e960a8e..6dc7988b23 100755 --- a/tests/integration/goldens/redis/google/cloud/redis_v1/services/cloud_redis/async_client.py +++ b/tests/integration/goldens/redis/google/cloud/redis_v1/services/cloud_redis/async_client.py @@ -178,7 +178,7 @@ def transport(self) -> CloudRedisTransport: return self._client.transport @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -1771,7 +1771,7 @@ async def sample_reschedule_maintenance(): async def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1797,6 +1797,8 @@ async def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.ListOperationsRequest(**request) @@ -1823,7 +1825,7 @@ async def list_operations( async def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1849,6 +1851,8 @@ async def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.GetOperationRequest(**request) @@ -1875,7 +1879,7 @@ async def get_operation( async def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1905,6 +1909,8 @@ async def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.DeleteOperationRequest(**request) @@ -1927,7 +1933,7 @@ async def delete_operation( async def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -1956,6 +1962,8 @@ async def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.CancelOperationRequest(**request) @@ -1978,7 +1986,7 @@ async def cancel_operation( async def wait_operation( self, - request: Optional[operations_pb2.WaitOperationRequest] = None, + request: Optional[Union[operations_pb2.WaitOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2010,6 +2018,8 @@ async def wait_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.WaitOperationRequest(**request) @@ -2036,7 +2046,7 @@ async def wait_operation( async def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2062,6 +2072,8 @@ async def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = locations_pb2.GetLocationRequest(**request) @@ -2088,7 +2100,7 @@ async def get_location( async def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2114,6 +2126,8 @@ async def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = locations_pb2.ListLocationsRequest(**request) diff --git a/tests/integration/goldens/redis/google/cloud/redis_v1/services/cloud_redis/client.py b/tests/integration/goldens/redis/google/cloud/redis_v1/services/cloud_redis/client.py index f3da10c2fc..79458fafe1 100755 --- a/tests/integration/goldens/redis/google/cloud/redis_v1/services/cloud_redis/client.py +++ b/tests/integration/goldens/redis/google/cloud/redis_v1/services/cloud_redis/client.py @@ -131,7 +131,7 @@ class CloudRedisClient(metaclass=CloudRedisClientMeta): """ @staticmethod - def _get_default_mtls_endpoint(api_endpoint): + def _get_default_mtls_endpoint(api_endpoint) -> Optional[str]: """Converts api endpoint to mTLS endpoint. Convert "*.sandbox.googleapis.com" and "*.googleapis.com" to @@ -139,7 +139,7 @@ def _get_default_mtls_endpoint(api_endpoint): Args: api_endpoint (Optional[str]): the api endpoint to convert. Returns: - str: converted mTLS api endpoint. + Optional[str]: converted mTLS api endpoint. """ if not api_endpoint: return api_endpoint @@ -149,6 +149,10 @@ def _get_default_mtls_endpoint(api_endpoint): ) m = mtls_endpoint_re.match(api_endpoint) + if m is None: + # could not parse api_endpoint; return as-is + return api_endpoint + name, mtls, sandbox, googledomain = m.groups() if mtls or not googledomain: return api_endpoint @@ -410,7 +414,7 @@ def _get_client_cert_source(provided_cert_source, use_cert_flag): return client_cert_source @staticmethod - def _get_api_endpoint(api_override, client_cert_source, universe_domain, use_mtls_endpoint): + def _get_api_endpoint(api_override, client_cert_source, universe_domain, use_mtls_endpoint) -> str: """Return the API endpoint used by the client. Args: @@ -496,7 +500,7 @@ def _add_cred_info_for_auth_errors( error._details.append(json.dumps(cred_info)) @property - def api_endpoint(self): + def api_endpoint(self) -> str: """Return the API endpoint used by the client instance. Returns: @@ -2176,7 +2180,7 @@ def __exit__(self, type, value, traceback): def list_operations( self, - request: Optional[operations_pb2.ListOperationsRequest] = None, + request: Optional[Union[operations_pb2.ListOperationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2202,6 +2206,8 @@ def list_operations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.ListOperationsRequest(**request) @@ -2232,7 +2238,7 @@ def list_operations( def get_operation( self, - request: Optional[operations_pb2.GetOperationRequest] = None, + request: Optional[Union[operations_pb2.GetOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2258,6 +2264,8 @@ def get_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.GetOperationRequest(**request) @@ -2288,7 +2296,7 @@ def get_operation( def delete_operation( self, - request: Optional[operations_pb2.DeleteOperationRequest] = None, + request: Optional[Union[operations_pb2.DeleteOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2318,6 +2326,8 @@ def delete_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.DeleteOperationRequest(**request) @@ -2340,7 +2350,7 @@ def delete_operation( def cancel_operation( self, - request: Optional[operations_pb2.CancelOperationRequest] = None, + request: Optional[Union[operations_pb2.CancelOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2369,6 +2379,8 @@ def cancel_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.CancelOperationRequest(**request) @@ -2391,7 +2403,7 @@ def cancel_operation( def wait_operation( self, - request: Optional[operations_pb2.WaitOperationRequest] = None, + request: Optional[Union[operations_pb2.WaitOperationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2423,6 +2435,8 @@ def wait_operation( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = operations_pb2.WaitOperationRequest(**request) @@ -2453,7 +2467,7 @@ def wait_operation( def get_location( self, - request: Optional[locations_pb2.GetLocationRequest] = None, + request: Optional[Union[locations_pb2.GetLocationRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2479,6 +2493,8 @@ def get_location( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = locations_pb2.GetLocationRequest(**request) @@ -2509,7 +2525,7 @@ def get_location( def list_locations( self, - request: Optional[locations_pb2.ListLocationsRequest] = None, + request: Optional[Union[locations_pb2.ListLocationsRequest, dict]] = None, *, retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: Union[float, object] = gapic_v1.method.DEFAULT, @@ -2535,6 +2551,8 @@ def list_locations( # Create or coerce a protobuf request object. # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. + if request is None: + request = {} if isinstance(request, dict): request = locations_pb2.ListLocationsRequest(**request) diff --git a/tests/integration/goldens/redis/google/cloud/redis_v1/services/cloud_redis/transports/grpc.py b/tests/integration/goldens/redis/google/cloud/redis_v1/services/cloud_redis/transports/grpc.py index ac164835f5..a460cbb67b 100755 --- a/tests/integration/goldens/redis/google/cloud/redis_v1/services/cloud_redis/transports/grpc.py +++ b/tests/integration/goldens/redis/google/cloud/redis_v1/services/cloud_redis/transports/grpc.py @@ -55,7 +55,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -86,7 +86,7 @@ def intercept_unary_unary(self, continuation, client_call_details, request): elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, diff --git a/tests/integration/goldens/redis/google/cloud/redis_v1/services/cloud_redis/transports/grpc_asyncio.py b/tests/integration/goldens/redis/google/cloud/redis_v1/services/cloud_redis/transports/grpc_asyncio.py index 46f96b5c5c..692cd77d36 100755 --- a/tests/integration/goldens/redis/google/cloud/redis_v1/services/cloud_redis/transports/grpc_asyncio.py +++ b/tests/integration/goldens/redis/google/cloud/redis_v1/services/cloud_redis/transports/grpc_asyncio.py @@ -59,7 +59,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(request, google.protobuf.message.Message): request_payload = MessageToJson(request) else: - request_payload = f"{type(request).__name__}: {pickle.dumps(request)}" + request_payload = f"{type(request).__name__}: {pickle.dumps(request)!r}" request_metadata = { key: value.decode("utf-8") if isinstance(value, bytes) else value @@ -90,7 +90,7 @@ async def intercept_unary_unary(self, continuation, client_call_details, request elif isinstance(result, google.protobuf.message.Message): response_payload = MessageToJson(result) else: - response_payload = f"{type(result).__name__}: {pickle.dumps(result)}" + response_payload = f"{type(result).__name__}: {pickle.dumps(result)!r}" grpc_response = { "payload": response_payload, "metadata": metadata, diff --git a/tests/integration/goldens/redis/noxfile.py b/tests/integration/goldens/redis/noxfile.py index d2fcf30488..2b6cbd1280 100755 --- a/tests/integration/goldens/redis/noxfile.py +++ b/tests/integration/goldens/redis/noxfile.py @@ -107,6 +107,8 @@ def mypy(session): "mypy", "-p", "google", + "--check-untyped-defs", + *session.posargs, ) diff --git a/tests/integration/goldens/redis/tests/unit/gapic/redis_v1/test_cloud_redis.py b/tests/integration/goldens/redis/tests/unit/gapic/redis_v1/test_cloud_redis.py index ae66b5a92c..255358ee2a 100755 --- a/tests/integration/goldens/redis/tests/unit/gapic/redis_v1/test_cloud_redis.py +++ b/tests/integration/goldens/redis/tests/unit/gapic/redis_v1/test_cloud_redis.py @@ -122,6 +122,7 @@ def test__get_default_mtls_endpoint(): sandbox_endpoint = "example.sandbox.googleapis.com" sandbox_mtls_endpoint = "example.mtls.sandbox.googleapis.com" non_googleapi = "api.example.com" + custom_endpoint = ".custom" assert CloudRedisClient._get_default_mtls_endpoint(None) is None assert CloudRedisClient._get_default_mtls_endpoint(api_endpoint) == api_mtls_endpoint @@ -129,6 +130,7 @@ def test__get_default_mtls_endpoint(): assert CloudRedisClient._get_default_mtls_endpoint(sandbox_endpoint) == sandbox_mtls_endpoint assert CloudRedisClient._get_default_mtls_endpoint(sandbox_mtls_endpoint) == sandbox_mtls_endpoint assert CloudRedisClient._get_default_mtls_endpoint(non_googleapi) == non_googleapi + assert CloudRedisClient._get_default_mtls_endpoint(custom_endpoint) == custom_endpoint def test__read_environment_variables(): assert CloudRedisClient._read_environment_variables() == (False, "auto", None) @@ -12222,6 +12224,37 @@ async def test_delete_operation_from_dict_async(): ) call.assert_called() +def test_delete_operation_flattened(): + client = CloudRedisClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() +@pytest.mark.asyncio +async def test_delete_operation_flattened_async(): + client = CloudRedisAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.delete_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + None + ) + await client.delete_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.DeleteOperationRequest() + def test_cancel_operation(transport: str = "grpc"): client = CloudRedisClient( @@ -12351,6 +12384,37 @@ async def test_cancel_operation_from_dict_async(): ) call.assert_called() +def test_cancel_operation_flattened(): + client = CloudRedisClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = None + + client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() +@pytest.mark.asyncio +async def test_cancel_operation_flattened_async(): + client = CloudRedisAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.cancel_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + None + ) + await client.cancel_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.CancelOperationRequest() + def test_wait_operation(transport: str = "grpc"): client = CloudRedisClient( credentials=ga_credentials.AnonymousCredentials(), transport=transport, @@ -12479,6 +12543,37 @@ async def test_wait_operation_from_dict_async(): ) call.assert_called() +def test_wait_operation_flattened(): + client = CloudRedisClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.wait_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.WaitOperationRequest() +@pytest.mark.asyncio +async def test_wait_operation_flattened_async(): + client = CloudRedisAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.wait_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.wait_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.WaitOperationRequest() + def test_get_operation(transport: str = "grpc"): client = CloudRedisClient( @@ -12608,6 +12703,37 @@ async def test_get_operation_from_dict_async(): ) call.assert_called() +def test_get_operation_flattened(): + client = CloudRedisClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.Operation() + + client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() +@pytest.mark.asyncio +async def test_get_operation_flattened_async(): + client = CloudRedisAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_operation), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.Operation() + ) + await client.get_operation() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.GetOperationRequest() + def test_list_operations(transport: str = "grpc"): client = CloudRedisClient( @@ -12737,6 +12863,37 @@ async def test_list_operations_from_dict_async(): ) call.assert_called() +def test_list_operations_flattened(): + client = CloudRedisClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = operations_pb2.ListOperationsResponse() + + client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() +@pytest.mark.asyncio +async def test_list_operations_flattened_async(): + client = CloudRedisAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_operations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + operations_pb2.ListOperationsResponse() + ) + await client.list_operations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == operations_pb2.ListOperationsRequest() + def test_list_locations(transport: str = "grpc"): client = CloudRedisClient( @@ -12866,6 +13023,37 @@ async def test_list_locations_from_dict_async(): ) call.assert_called() +def test_list_locations_flattened(): + client = CloudRedisClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.ListLocationsResponse() + + client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() +@pytest.mark.asyncio +async def test_list_locations_flattened_async(): + client = CloudRedisAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.list_locations), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.ListLocationsResponse() + ) + await client.list_locations() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.ListLocationsRequest() + def test_get_location(transport: str = "grpc"): client = CloudRedisClient( @@ -12994,6 +13182,37 @@ async def test_get_location_from_dict_async(): ) call.assert_called() +def test_get_location_flattened(): + client = CloudRedisClient( + credentials=ga_credentials.AnonymousCredentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = locations_pb2.Location() + + client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() +@pytest.mark.asyncio +async def test_get_location_flattened_async(): + client = CloudRedisAsyncClient( + credentials=async_anonymous_credentials(), + ) + # Mock the actual call within the gRPC stub, and fake the request. + with mock.patch.object(type(client.transport.get_location), "__call__") as call: + # Designate an appropriate return value for the call. + call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( + locations_pb2.Location() + ) + await client.get_location() + # Establish that the underlying gRPC stub method was called. + assert len(call.mock_calls) == 1 + _, args, _ = call.mock_calls[0] + assert args[0] == locations_pb2.GetLocationRequest() + def test_transport_close_grpc(): client = CloudRedisClient( From 10007c25b8b47aa6a160ae76155a7cedccb40b6b Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Tue, 20 Jan 2026 19:58:16 -0800 Subject: [PATCH 22/26] updated api_endpoint type --- .../%name_%version/%sub/services/%service/client.py.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gapic/templates/%namespace/%name_%version/%sub/services/%service/client.py.j2 b/gapic/templates/%namespace/%name_%version/%sub/services/%service/client.py.j2 index 301f9d5347..7842199a03 100644 --- a/gapic/templates/%namespace/%name_%version/%sub/services/%service/client.py.j2 +++ b/gapic/templates/%namespace/%name_%version/%sub/services/%service/client.py.j2 @@ -567,7 +567,7 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta): self._use_client_cert, self._use_mtls_endpoint, self._universe_domain_env = {{ service.client_name }}._read_environment_variables() self._client_cert_source = {{ service.client_name }}._get_client_cert_source(self._client_options.client_cert_source, self._use_client_cert) self._universe_domain = {{ service.client_name }}._get_universe_domain(universe_domain_opt, self._universe_domain_env) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False From 1a3afcd9c49385bc3733b23df52379db655124ee Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Tue, 20 Jan 2026 20:25:34 -0800 Subject: [PATCH 23/26] set api_endpoint to empty string --- .../%name_%version/%sub/services/%service/client.py.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gapic/templates/%namespace/%name_%version/%sub/services/%service/client.py.j2 b/gapic/templates/%namespace/%name_%version/%sub/services/%service/client.py.j2 index 7842199a03..e3863159c4 100644 --- a/gapic/templates/%namespace/%name_%version/%sub/services/%service/client.py.j2 +++ b/gapic/templates/%namespace/%name_%version/%sub/services/%service/client.py.j2 @@ -567,7 +567,7 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta): self._use_client_cert, self._use_mtls_endpoint, self._universe_domain_env = {{ service.client_name }}._read_environment_variables() self._client_cert_source = {{ service.client_name }}._get_client_cert_source(self._client_options.client_cert_source, self._use_client_cert) self._universe_domain = {{ service.client_name }}._get_universe_domain(universe_domain_opt, self._universe_domain_env) - self._api_endpoint: str # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False From 51b22532415b3bfb50c9b1e44d6bd264fe3f82ce Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Tue, 20 Jan 2026 23:16:47 -0800 Subject: [PATCH 24/26] updated goldens --- .../services/asset_service/async_client.py | 12 +- .../asset_v1/services/asset_service/client.py | 2 +- .../services/iam_credentials/client.py | 2 +- .../services/eventarc/async_client.py | 108 ++++++++++------- .../eventarc_v1/services/eventarc/client.py | 110 ++++++++++-------- .../config_service_v2/async_client.py | 36 +++--- .../services/config_service_v2/client.py | 38 +++--- .../logging_service_v2/async_client.py | 36 +++--- .../services/logging_service_v2/client.py | 38 +++--- .../metrics_service_v2/async_client.py | 36 +++--- .../services/metrics_service_v2/client.py | 38 +++--- .../config_service_v2/async_client.py | 36 +++--- .../services/config_service_v2/client.py | 38 +++--- .../logging_service_v2/async_client.py | 36 +++--- .../services/logging_service_v2/client.py | 38 +++--- .../metrics_service_v2/async_client.py | 36 +++--- .../services/metrics_service_v2/client.py | 38 +++--- .../services/cloud_redis/async_client.py | 84 +++++++------ .../redis_v1/services/cloud_redis/client.py | 86 ++++++++------ .../services/cloud_redis/async_client.py | 84 +++++++------ .../redis_v1/services/cloud_redis/client.py | 86 ++++++++------ 21 files changed, 592 insertions(+), 426 deletions(-) diff --git a/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/async_client.py b/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/async_client.py index 8ae1ec3272..110df677f9 100755 --- a/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/async_client.py +++ b/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/async_client.py @@ -3181,9 +3181,11 @@ async def get_operation( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3193,7 +3195,7 @@ async def get_operation( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. @@ -3201,7 +3203,7 @@ async def get_operation( # Send the request. response = await rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response diff --git a/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/client.py b/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/client.py index 15f093bdba..13571943a3 100755 --- a/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/client.py +++ b/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/client.py @@ -623,7 +623,7 @@ def __init__(self, *, self._use_client_cert, self._use_mtls_endpoint, self._universe_domain_env = AssetServiceClient._read_environment_variables() self._client_cert_source = AssetServiceClient._get_client_cert_source(self._client_options.client_cert_source, self._use_client_cert) self._universe_domain = AssetServiceClient._get_universe_domain(universe_domain_opt, self._universe_domain_env) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/tests/integration/goldens/credentials/google/iam/credentials_v1/services/iam_credentials/client.py b/tests/integration/goldens/credentials/google/iam/credentials_v1/services/iam_credentials/client.py index 61ea24f38e..db6a2a63fa 100755 --- a/tests/integration/goldens/credentials/google/iam/credentials_v1/services/iam_credentials/client.py +++ b/tests/integration/goldens/credentials/google/iam/credentials_v1/services/iam_credentials/client.py @@ -560,7 +560,7 @@ def __init__(self, *, self._use_client_cert, self._use_mtls_endpoint, self._universe_domain_env = IAMCredentialsClient._read_environment_variables() self._client_cert_source = IAMCredentialsClient._get_client_cert_source(self._client_options.client_cert_source, self._use_client_cert) self._universe_domain = IAMCredentialsClient._get_universe_domain(universe_domain_opt, self._universe_domain_env) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False diff --git a/tests/integration/goldens/eventarc/google/cloud/eventarc_v1/services/eventarc/async_client.py b/tests/integration/goldens/eventarc/google/cloud/eventarc_v1/services/eventarc/async_client.py index e20efdef99..06c2fa9dcd 100755 --- a/tests/integration/goldens/eventarc/google/cloud/eventarc_v1/services/eventarc/async_client.py +++ b/tests/integration/goldens/eventarc/google/cloud/eventarc_v1/services/eventarc/async_client.py @@ -2577,9 +2577,11 @@ async def list_operations( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2589,7 +2591,7 @@ async def list_operations( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. @@ -2597,7 +2599,7 @@ async def list_operations( # Send the request. response = await rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -2631,9 +2633,11 @@ async def get_operation( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2643,7 +2647,7 @@ async def get_operation( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. @@ -2651,7 +2655,7 @@ async def get_operation( # Send the request. response = await rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -2689,9 +2693,11 @@ async def delete_operation( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2701,14 +2707,14 @@ async def delete_operation( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. self._client._validate_universe_domain() # Send the request. - await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + await rpc(request_pb, retry=retry, timeout=timeout, metadata=metadata,) async def cancel_operation( self, @@ -2742,9 +2748,11 @@ async def cancel_operation( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2754,14 +2762,14 @@ async def cancel_operation( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. self._client._validate_universe_domain() # Send the request. - await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + await rpc(request_pb, retry=retry, timeout=timeout, metadata=metadata,) async def set_iam_policy( self, @@ -2858,9 +2866,11 @@ async def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2870,7 +2880,7 @@ async def set_iam_policy( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("resource", request.resource),)), + (("resource", request_pb.resource),)), ) # Validate the universe domain. @@ -2878,7 +2888,7 @@ async def set_iam_policy( # Send the request. response = await rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -2979,9 +2989,11 @@ async def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2991,7 +3003,7 @@ async def get_iam_policy( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("resource", request.resource),)), + (("resource", request_pb.resource),)), ) # Validate the universe domain. @@ -2999,7 +3011,7 @@ async def get_iam_policy( # Send the request. response = await rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -3038,9 +3050,11 @@ async def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3050,7 +3064,7 @@ async def test_iam_permissions( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("resource", request.resource),)), + (("resource", request_pb.resource),)), ) # Validate the universe domain. @@ -3058,7 +3072,7 @@ async def test_iam_permissions( # Send the request. response = await rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -3092,9 +3106,11 @@ async def get_location( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3104,7 +3120,7 @@ async def get_location( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. @@ -3112,7 +3128,7 @@ async def get_location( # Send the request. response = await rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -3146,9 +3162,11 @@ async def list_locations( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3158,7 +3176,7 @@ async def list_locations( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. @@ -3166,7 +3184,7 @@ async def list_locations( # Send the request. response = await rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response diff --git a/tests/integration/goldens/eventarc/google/cloud/eventarc_v1/services/eventarc/client.py b/tests/integration/goldens/eventarc/google/cloud/eventarc_v1/services/eventarc/client.py index e804c0f879..b0dcd0018d 100755 --- a/tests/integration/goldens/eventarc/google/cloud/eventarc_v1/services/eventarc/client.py +++ b/tests/integration/goldens/eventarc/google/cloud/eventarc_v1/services/eventarc/client.py @@ -668,7 +668,7 @@ def __init__(self, *, self._use_client_cert, self._use_mtls_endpoint, self._universe_domain_env = EventarcClient._read_environment_variables() self._client_cert_source = EventarcClient._get_client_cert_source(self._client_options.client_cert_source, self._use_client_cert) self._universe_domain = EventarcClient._get_universe_domain(universe_domain_opt, self._universe_domain_env) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -3028,9 +3028,11 @@ def list_operations( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3040,7 +3042,7 @@ def list_operations( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. @@ -3049,7 +3051,7 @@ def list_operations( try: # Send the request. response = rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -3086,9 +3088,11 @@ def get_operation( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3098,7 +3102,7 @@ def get_operation( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. @@ -3107,7 +3111,7 @@ def get_operation( try: # Send the request. response = rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -3148,9 +3152,11 @@ def delete_operation( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3160,14 +3166,14 @@ def delete_operation( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. self._validate_universe_domain() # Send the request. - rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + rpc(request_pb, retry=retry, timeout=timeout, metadata=metadata,) def cancel_operation( self, @@ -3201,9 +3207,11 @@ def cancel_operation( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3213,14 +3221,14 @@ def cancel_operation( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. self._validate_universe_domain() # Send the request. - rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + rpc(request_pb, retry=retry, timeout=timeout, metadata=metadata,) def set_iam_policy( self, @@ -3317,9 +3325,11 @@ def set_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = iam_policy_pb2.SetIamPolicyRequest(**request) + request_pb = iam_policy_pb2.SetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.SetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3329,7 +3339,7 @@ def set_iam_policy( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("resource", request.resource),)), + (("resource", request_pb.resource),)), ) # Validate the universe domain. @@ -3338,7 +3348,7 @@ def set_iam_policy( try: # Send the request. response = rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -3442,9 +3452,11 @@ def get_iam_policy( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = iam_policy_pb2.GetIamPolicyRequest(**request) + request_pb = iam_policy_pb2.GetIamPolicyRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.GetIamPolicyRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3454,7 +3466,7 @@ def get_iam_policy( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("resource", request.resource),)), + (("resource", request_pb.resource),)), ) # Validate the universe domain. @@ -3463,7 +3475,7 @@ def get_iam_policy( try: # Send the request. response = rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -3505,9 +3517,11 @@ def test_iam_permissions( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = iam_policy_pb2.TestIamPermissionsRequest(**request) + request_pb = iam_policy_pb2.TestIamPermissionsRequest() + elif isinstance(request, dict): + request_pb = iam_policy_pb2.TestIamPermissionsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3517,7 +3531,7 @@ def test_iam_permissions( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("resource", request.resource),)), + (("resource", request_pb.resource),)), ) # Validate the universe domain. @@ -3526,7 +3540,7 @@ def test_iam_permissions( try: # Send the request. response = rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -3563,9 +3577,11 @@ def get_location( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3575,7 +3591,7 @@ def get_location( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. @@ -3584,7 +3600,7 @@ def get_location( try: # Send the request. response = rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -3621,9 +3637,11 @@ def list_locations( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3633,7 +3651,7 @@ def list_locations( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. @@ -3642,7 +3660,7 @@ def list_locations( try: # Send the request. response = rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response diff --git a/tests/integration/goldens/logging/google/cloud/logging_v2/services/config_service_v2/async_client.py b/tests/integration/goldens/logging/google/cloud/logging_v2/services/config_service_v2/async_client.py index b3264d843e..668a5f6736 100755 --- a/tests/integration/goldens/logging/google/cloud/logging_v2/services/config_service_v2/async_client.py +++ b/tests/integration/goldens/logging/google/cloud/logging_v2/services/config_service_v2/async_client.py @@ -3925,9 +3925,11 @@ async def list_operations( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3937,7 +3939,7 @@ async def list_operations( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. @@ -3945,7 +3947,7 @@ async def list_operations( # Send the request. response = await rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -3979,9 +3981,11 @@ async def get_operation( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3991,7 +3995,7 @@ async def get_operation( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. @@ -3999,7 +4003,7 @@ async def get_operation( # Send the request. response = await rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -4036,9 +4040,11 @@ async def cancel_operation( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4048,14 +4054,14 @@ async def cancel_operation( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. self._client._validate_universe_domain() # Send the request. - await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + await rpc(request_pb, retry=retry, timeout=timeout, metadata=metadata,) async def __aenter__(self) -> "ConfigServiceV2AsyncClient": return self diff --git a/tests/integration/goldens/logging/google/cloud/logging_v2/services/config_service_v2/client.py b/tests/integration/goldens/logging/google/cloud/logging_v2/services/config_service_v2/client.py index 0d13aee340..329d5ea9c7 100755 --- a/tests/integration/goldens/logging/google/cloud/logging_v2/services/config_service_v2/client.py +++ b/tests/integration/goldens/logging/google/cloud/logging_v2/services/config_service_v2/client.py @@ -616,7 +616,7 @@ def __init__(self, *, self._use_client_cert, self._use_mtls_endpoint, self._universe_domain_env = ConfigServiceV2Client._read_environment_variables() self._client_cert_source = ConfigServiceV2Client._get_client_cert_source(self._client_options.client_cert_source, self._use_client_cert) self._universe_domain = ConfigServiceV2Client._get_universe_domain(universe_domain_opt, self._universe_domain_env) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -4347,9 +4347,11 @@ def list_operations( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4359,7 +4361,7 @@ def list_operations( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. @@ -4368,7 +4370,7 @@ def list_operations( try: # Send the request. response = rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -4405,9 +4407,11 @@ def get_operation( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4417,7 +4421,7 @@ def get_operation( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. @@ -4426,7 +4430,7 @@ def get_operation( try: # Send the request. response = rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -4466,9 +4470,11 @@ def cancel_operation( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4478,14 +4484,14 @@ def cancel_operation( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. self._validate_universe_domain() # Send the request. - rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + rpc(request_pb, retry=retry, timeout=timeout, metadata=metadata,) diff --git a/tests/integration/goldens/logging/google/cloud/logging_v2/services/logging_service_v2/async_client.py b/tests/integration/goldens/logging/google/cloud/logging_v2/services/logging_service_v2/async_client.py index 953c59eb4a..0ea020707a 100755 --- a/tests/integration/goldens/logging/google/cloud/logging_v2/services/logging_service_v2/async_client.py +++ b/tests/integration/goldens/logging/google/cloud/logging_v2/services/logging_service_v2/async_client.py @@ -1040,9 +1040,11 @@ async def list_operations( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1052,7 +1054,7 @@ async def list_operations( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. @@ -1060,7 +1062,7 @@ async def list_operations( # Send the request. response = await rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -1094,9 +1096,11 @@ async def get_operation( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1106,7 +1110,7 @@ async def get_operation( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. @@ -1114,7 +1118,7 @@ async def get_operation( # Send the request. response = await rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -1151,9 +1155,11 @@ async def cancel_operation( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1163,14 +1169,14 @@ async def cancel_operation( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. self._client._validate_universe_domain() # Send the request. - await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + await rpc(request_pb, retry=retry, timeout=timeout, metadata=metadata,) async def __aenter__(self) -> "LoggingServiceV2AsyncClient": return self diff --git a/tests/integration/goldens/logging/google/cloud/logging_v2/services/logging_service_v2/client.py b/tests/integration/goldens/logging/google/cloud/logging_v2/services/logging_service_v2/client.py index 3c2e5510eb..5ea5f377e3 100755 --- a/tests/integration/goldens/logging/google/cloud/logging_v2/services/logging_service_v2/client.py +++ b/tests/integration/goldens/logging/google/cloud/logging_v2/services/logging_service_v2/client.py @@ -547,7 +547,7 @@ def __init__(self, *, self._use_client_cert, self._use_mtls_endpoint, self._universe_domain_env = LoggingServiceV2Client._read_environment_variables() self._client_cert_source = LoggingServiceV2Client._get_client_cert_source(self._client_options.client_cert_source, self._use_client_cert) self._universe_domain = LoggingServiceV2Client._get_universe_domain(universe_domain_opt, self._universe_domain_env) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1421,9 +1421,11 @@ def list_operations( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1433,7 +1435,7 @@ def list_operations( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. @@ -1442,7 +1444,7 @@ def list_operations( try: # Send the request. response = rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -1479,9 +1481,11 @@ def get_operation( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1491,7 +1495,7 @@ def get_operation( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. @@ -1500,7 +1504,7 @@ def get_operation( try: # Send the request. response = rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -1540,9 +1544,11 @@ def cancel_operation( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1552,14 +1558,14 @@ def cancel_operation( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. self._validate_universe_domain() # Send the request. - rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + rpc(request_pb, retry=retry, timeout=timeout, metadata=metadata,) diff --git a/tests/integration/goldens/logging/google/cloud/logging_v2/services/metrics_service_v2/async_client.py b/tests/integration/goldens/logging/google/cloud/logging_v2/services/metrics_service_v2/async_client.py index 81d65166a4..e03b06353d 100755 --- a/tests/integration/goldens/logging/google/cloud/logging_v2/services/metrics_service_v2/async_client.py +++ b/tests/integration/goldens/logging/google/cloud/logging_v2/services/metrics_service_v2/async_client.py @@ -891,9 +891,11 @@ async def list_operations( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -903,7 +905,7 @@ async def list_operations( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. @@ -911,7 +913,7 @@ async def list_operations( # Send the request. response = await rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -945,9 +947,11 @@ async def get_operation( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -957,7 +961,7 @@ async def get_operation( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. @@ -965,7 +969,7 @@ async def get_operation( # Send the request. response = await rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -1002,9 +1006,11 @@ async def cancel_operation( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1014,14 +1020,14 @@ async def cancel_operation( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. self._client._validate_universe_domain() # Send the request. - await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + await rpc(request_pb, retry=retry, timeout=timeout, metadata=metadata,) async def __aenter__(self) -> "MetricsServiceV2AsyncClient": return self diff --git a/tests/integration/goldens/logging/google/cloud/logging_v2/services/metrics_service_v2/client.py b/tests/integration/goldens/logging/google/cloud/logging_v2/services/metrics_service_v2/client.py index 36b5118970..07e388422c 100755 --- a/tests/integration/goldens/logging/google/cloud/logging_v2/services/metrics_service_v2/client.py +++ b/tests/integration/goldens/logging/google/cloud/logging_v2/services/metrics_service_v2/client.py @@ -548,7 +548,7 @@ def __init__(self, *, self._use_client_cert, self._use_mtls_endpoint, self._universe_domain_env = MetricsServiceV2Client._read_environment_variables() self._client_cert_source = MetricsServiceV2Client._get_client_cert_source(self._client_options.client_cert_source, self._use_client_cert) self._universe_domain = MetricsServiceV2Client._get_universe_domain(universe_domain_opt, self._universe_domain_env) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1272,9 +1272,11 @@ def list_operations( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1284,7 +1286,7 @@ def list_operations( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. @@ -1293,7 +1295,7 @@ def list_operations( try: # Send the request. response = rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -1330,9 +1332,11 @@ def get_operation( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1342,7 +1346,7 @@ def get_operation( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. @@ -1351,7 +1355,7 @@ def get_operation( try: # Send the request. response = rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -1391,9 +1395,11 @@ def cancel_operation( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1403,14 +1409,14 @@ def cancel_operation( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. self._validate_universe_domain() # Send the request. - rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + rpc(request_pb, retry=retry, timeout=timeout, metadata=metadata,) diff --git a/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/config_service_v2/async_client.py b/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/config_service_v2/async_client.py index 39e0cf65e4..405b7cbfa6 100755 --- a/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/config_service_v2/async_client.py +++ b/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/config_service_v2/async_client.py @@ -3925,9 +3925,11 @@ async def list_operations( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3937,7 +3939,7 @@ async def list_operations( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. @@ -3945,7 +3947,7 @@ async def list_operations( # Send the request. response = await rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -3979,9 +3981,11 @@ async def get_operation( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -3991,7 +3995,7 @@ async def get_operation( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. @@ -3999,7 +4003,7 @@ async def get_operation( # Send the request. response = await rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -4036,9 +4040,11 @@ async def cancel_operation( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4048,14 +4054,14 @@ async def cancel_operation( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. self._client._validate_universe_domain() # Send the request. - await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + await rpc(request_pb, retry=retry, timeout=timeout, metadata=metadata,) async def __aenter__(self) -> "BaseConfigServiceV2AsyncClient": return self diff --git a/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/config_service_v2/client.py b/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/config_service_v2/client.py index 6c4eaf85e4..555d247508 100755 --- a/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/config_service_v2/client.py +++ b/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/config_service_v2/client.py @@ -616,7 +616,7 @@ def __init__(self, *, self._use_client_cert, self._use_mtls_endpoint, self._universe_domain_env = BaseConfigServiceV2Client._read_environment_variables() self._client_cert_source = BaseConfigServiceV2Client._get_client_cert_source(self._client_options.client_cert_source, self._use_client_cert) self._universe_domain = BaseConfigServiceV2Client._get_universe_domain(universe_domain_opt, self._universe_domain_env) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -4347,9 +4347,11 @@ def list_operations( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4359,7 +4361,7 @@ def list_operations( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. @@ -4368,7 +4370,7 @@ def list_operations( try: # Send the request. response = rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -4405,9 +4407,11 @@ def get_operation( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4417,7 +4421,7 @@ def get_operation( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. @@ -4426,7 +4430,7 @@ def get_operation( try: # Send the request. response = rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -4466,9 +4470,11 @@ def cancel_operation( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -4478,14 +4484,14 @@ def cancel_operation( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. self._validate_universe_domain() # Send the request. - rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + rpc(request_pb, retry=retry, timeout=timeout, metadata=metadata,) diff --git a/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/logging_service_v2/async_client.py b/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/logging_service_v2/async_client.py index 953c59eb4a..0ea020707a 100755 --- a/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/logging_service_v2/async_client.py +++ b/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/logging_service_v2/async_client.py @@ -1040,9 +1040,11 @@ async def list_operations( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1052,7 +1054,7 @@ async def list_operations( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. @@ -1060,7 +1062,7 @@ async def list_operations( # Send the request. response = await rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -1094,9 +1096,11 @@ async def get_operation( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1106,7 +1110,7 @@ async def get_operation( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. @@ -1114,7 +1118,7 @@ async def get_operation( # Send the request. response = await rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -1151,9 +1155,11 @@ async def cancel_operation( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1163,14 +1169,14 @@ async def cancel_operation( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. self._client._validate_universe_domain() # Send the request. - await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + await rpc(request_pb, retry=retry, timeout=timeout, metadata=metadata,) async def __aenter__(self) -> "LoggingServiceV2AsyncClient": return self diff --git a/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/logging_service_v2/client.py b/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/logging_service_v2/client.py index 3c2e5510eb..5ea5f377e3 100755 --- a/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/logging_service_v2/client.py +++ b/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/logging_service_v2/client.py @@ -547,7 +547,7 @@ def __init__(self, *, self._use_client_cert, self._use_mtls_endpoint, self._universe_domain_env = LoggingServiceV2Client._read_environment_variables() self._client_cert_source = LoggingServiceV2Client._get_client_cert_source(self._client_options.client_cert_source, self._use_client_cert) self._universe_domain = LoggingServiceV2Client._get_universe_domain(universe_domain_opt, self._universe_domain_env) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1421,9 +1421,11 @@ def list_operations( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1433,7 +1435,7 @@ def list_operations( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. @@ -1442,7 +1444,7 @@ def list_operations( try: # Send the request. response = rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -1479,9 +1481,11 @@ def get_operation( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1491,7 +1495,7 @@ def get_operation( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. @@ -1500,7 +1504,7 @@ def get_operation( try: # Send the request. response = rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -1540,9 +1544,11 @@ def cancel_operation( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1552,14 +1558,14 @@ def cancel_operation( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. self._validate_universe_domain() # Send the request. - rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + rpc(request_pb, retry=retry, timeout=timeout, metadata=metadata,) diff --git a/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/metrics_service_v2/async_client.py b/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/metrics_service_v2/async_client.py index 93835fcc77..bb936503b4 100755 --- a/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/metrics_service_v2/async_client.py +++ b/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/metrics_service_v2/async_client.py @@ -891,9 +891,11 @@ async def list_operations( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -903,7 +905,7 @@ async def list_operations( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. @@ -911,7 +913,7 @@ async def list_operations( # Send the request. response = await rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -945,9 +947,11 @@ async def get_operation( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -957,7 +961,7 @@ async def get_operation( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. @@ -965,7 +969,7 @@ async def get_operation( # Send the request. response = await rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -1002,9 +1006,11 @@ async def cancel_operation( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1014,14 +1020,14 @@ async def cancel_operation( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. self._client._validate_universe_domain() # Send the request. - await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + await rpc(request_pb, retry=retry, timeout=timeout, metadata=metadata,) async def __aenter__(self) -> "BaseMetricsServiceV2AsyncClient": return self diff --git a/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/metrics_service_v2/client.py b/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/metrics_service_v2/client.py index 9331bc5b91..5b98796413 100755 --- a/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/metrics_service_v2/client.py +++ b/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/metrics_service_v2/client.py @@ -548,7 +548,7 @@ def __init__(self, *, self._use_client_cert, self._use_mtls_endpoint, self._universe_domain_env = BaseMetricsServiceV2Client._read_environment_variables() self._client_cert_source = BaseMetricsServiceV2Client._get_client_cert_source(self._client_options.client_cert_source, self._use_client_cert) self._universe_domain = BaseMetricsServiceV2Client._get_universe_domain(universe_domain_opt, self._universe_domain_env) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1272,9 +1272,11 @@ def list_operations( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1284,7 +1286,7 @@ def list_operations( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. @@ -1293,7 +1295,7 @@ def list_operations( try: # Send the request. response = rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -1330,9 +1332,11 @@ def get_operation( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1342,7 +1346,7 @@ def get_operation( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. @@ -1351,7 +1355,7 @@ def get_operation( try: # Send the request. response = rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -1391,9 +1395,11 @@ def cancel_operation( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1403,14 +1409,14 @@ def cancel_operation( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. self._validate_universe_domain() # Send the request. - rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + rpc(request_pb, retry=retry, timeout=timeout, metadata=metadata,) diff --git a/tests/integration/goldens/redis/google/cloud/redis_v1/services/cloud_redis/async_client.py b/tests/integration/goldens/redis/google/cloud/redis_v1/services/cloud_redis/async_client.py index 6dc7988b23..f496a43c8b 100755 --- a/tests/integration/goldens/redis/google/cloud/redis_v1/services/cloud_redis/async_client.py +++ b/tests/integration/goldens/redis/google/cloud/redis_v1/services/cloud_redis/async_client.py @@ -1798,9 +1798,11 @@ async def list_operations( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1810,7 +1812,7 @@ async def list_operations( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. @@ -1818,7 +1820,7 @@ async def list_operations( # Send the request. response = await rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -1852,9 +1854,11 @@ async def get_operation( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1864,7 +1868,7 @@ async def get_operation( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. @@ -1872,7 +1876,7 @@ async def get_operation( # Send the request. response = await rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -1910,9 +1914,11 @@ async def delete_operation( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1922,14 +1928,14 @@ async def delete_operation( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. self._client._validate_universe_domain() # Send the request. - await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + await rpc(request_pb, retry=retry, timeout=timeout, metadata=metadata,) async def cancel_operation( self, @@ -1963,9 +1969,11 @@ async def cancel_operation( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1975,14 +1983,14 @@ async def cancel_operation( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. self._client._validate_universe_domain() # Send the request. - await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + await rpc(request_pb, retry=retry, timeout=timeout, metadata=metadata,) async def wait_operation( self, @@ -2019,9 +2027,11 @@ async def wait_operation( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.WaitOperationRequest(**request) + request_pb = operations_pb2.WaitOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.WaitOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2031,7 +2041,7 @@ async def wait_operation( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. @@ -2039,7 +2049,7 @@ async def wait_operation( # Send the request. response = await rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -2073,9 +2083,11 @@ async def get_location( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2085,7 +2097,7 @@ async def get_location( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. @@ -2093,7 +2105,7 @@ async def get_location( # Send the request. response = await rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -2127,9 +2139,11 @@ async def list_locations( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2139,7 +2153,7 @@ async def list_locations( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. @@ -2147,7 +2161,7 @@ async def list_locations( # Send the request. response = await rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response diff --git a/tests/integration/goldens/redis/google/cloud/redis_v1/services/cloud_redis/client.py b/tests/integration/goldens/redis/google/cloud/redis_v1/services/cloud_redis/client.py index 79458fafe1..f17dc10e34 100755 --- a/tests/integration/goldens/redis/google/cloud/redis_v1/services/cloud_redis/client.py +++ b/tests/integration/goldens/redis/google/cloud/redis_v1/services/cloud_redis/client.py @@ -587,7 +587,7 @@ def __init__(self, *, self._use_client_cert, self._use_mtls_endpoint, self._universe_domain_env = CloudRedisClient._read_environment_variables() self._client_cert_source = CloudRedisClient._get_client_cert_source(self._client_options.client_cert_source, self._use_client_cert) self._universe_domain = CloudRedisClient._get_universe_domain(universe_domain_opt, self._universe_domain_env) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -2207,9 +2207,11 @@ def list_operations( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2219,7 +2221,7 @@ def list_operations( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. @@ -2228,7 +2230,7 @@ def list_operations( try: # Send the request. response = rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -2265,9 +2267,11 @@ def get_operation( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2277,7 +2281,7 @@ def get_operation( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. @@ -2286,7 +2290,7 @@ def get_operation( try: # Send the request. response = rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -2327,9 +2331,11 @@ def delete_operation( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2339,14 +2345,14 @@ def delete_operation( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. self._validate_universe_domain() # Send the request. - rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + rpc(request_pb, retry=retry, timeout=timeout, metadata=metadata,) def cancel_operation( self, @@ -2380,9 +2386,11 @@ def cancel_operation( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2392,14 +2400,14 @@ def cancel_operation( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. self._validate_universe_domain() # Send the request. - rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + rpc(request_pb, retry=retry, timeout=timeout, metadata=metadata,) def wait_operation( self, @@ -2436,9 +2444,11 @@ def wait_operation( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.WaitOperationRequest(**request) + request_pb = operations_pb2.WaitOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.WaitOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2448,7 +2458,7 @@ def wait_operation( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. @@ -2457,7 +2467,7 @@ def wait_operation( try: # Send the request. response = rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -2494,9 +2504,11 @@ def get_location( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2506,7 +2518,7 @@ def get_location( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. @@ -2515,7 +2527,7 @@ def get_location( try: # Send the request. response = rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -2552,9 +2564,11 @@ def list_locations( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -2564,7 +2578,7 @@ def list_locations( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. @@ -2573,7 +2587,7 @@ def list_locations( try: # Send the request. response = rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response diff --git a/tests/integration/goldens/redis_selective/google/cloud/redis_v1/services/cloud_redis/async_client.py b/tests/integration/goldens/redis_selective/google/cloud/redis_v1/services/cloud_redis/async_client.py index 4ada4daa32..e703d95677 100755 --- a/tests/integration/goldens/redis_selective/google/cloud/redis_v1/services/cloud_redis/async_client.py +++ b/tests/integration/goldens/redis_selective/google/cloud/redis_v1/services/cloud_redis/async_client.py @@ -991,9 +991,11 @@ async def list_operations( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1003,7 +1005,7 @@ async def list_operations( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. @@ -1011,7 +1013,7 @@ async def list_operations( # Send the request. response = await rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -1045,9 +1047,11 @@ async def get_operation( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1057,7 +1061,7 @@ async def get_operation( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. @@ -1065,7 +1069,7 @@ async def get_operation( # Send the request. response = await rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -1103,9 +1107,11 @@ async def delete_operation( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1115,14 +1121,14 @@ async def delete_operation( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. self._client._validate_universe_domain() # Send the request. - await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + await rpc(request_pb, retry=retry, timeout=timeout, metadata=metadata,) async def cancel_operation( self, @@ -1156,9 +1162,11 @@ async def cancel_operation( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1168,14 +1176,14 @@ async def cancel_operation( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. self._client._validate_universe_domain() # Send the request. - await rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + await rpc(request_pb, retry=retry, timeout=timeout, metadata=metadata,) async def wait_operation( self, @@ -1212,9 +1220,11 @@ async def wait_operation( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.WaitOperationRequest(**request) + request_pb = operations_pb2.WaitOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.WaitOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1224,7 +1234,7 @@ async def wait_operation( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. @@ -1232,7 +1242,7 @@ async def wait_operation( # Send the request. response = await rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -1266,9 +1276,11 @@ async def get_location( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1278,7 +1290,7 @@ async def get_location( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. @@ -1286,7 +1298,7 @@ async def get_location( # Send the request. response = await rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -1320,9 +1332,11 @@ async def list_locations( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1332,7 +1346,7 @@ async def list_locations( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. @@ -1340,7 +1354,7 @@ async def list_locations( # Send the request. response = await rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response diff --git a/tests/integration/goldens/redis_selective/google/cloud/redis_v1/services/cloud_redis/client.py b/tests/integration/goldens/redis_selective/google/cloud/redis_v1/services/cloud_redis/client.py index 2ec0f8709e..b3ad484bc1 100755 --- a/tests/integration/goldens/redis_selective/google/cloud/redis_v1/services/cloud_redis/client.py +++ b/tests/integration/goldens/redis_selective/google/cloud/redis_v1/services/cloud_redis/client.py @@ -587,7 +587,7 @@ def __init__(self, *, self._use_client_cert, self._use_mtls_endpoint, self._universe_domain_env = CloudRedisClient._read_environment_variables() self._client_cert_source = CloudRedisClient._get_client_cert_source(self._client_options.client_cert_source, self._use_client_cert) self._universe_domain = CloudRedisClient._get_universe_domain(universe_domain_opt, self._universe_domain_env) - self._api_endpoint = None # updated below, depending on `transport` + self._api_endpoint: str = "" # updated below, depending on `transport` # Initialize the universe domain validation. self._is_universe_domain_valid = False @@ -1406,9 +1406,11 @@ def list_operations( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.ListOperationsRequest(**request) + request_pb = operations_pb2.ListOperationsRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.ListOperationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1418,7 +1420,7 @@ def list_operations( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. @@ -1427,7 +1429,7 @@ def list_operations( try: # Send the request. response = rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -1464,9 +1466,11 @@ def get_operation( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.GetOperationRequest(**request) + request_pb = operations_pb2.GetOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.GetOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1476,7 +1480,7 @@ def get_operation( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. @@ -1485,7 +1489,7 @@ def get_operation( try: # Send the request. response = rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -1526,9 +1530,11 @@ def delete_operation( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.DeleteOperationRequest(**request) + request_pb = operations_pb2.DeleteOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.DeleteOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1538,14 +1544,14 @@ def delete_operation( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. self._validate_universe_domain() # Send the request. - rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + rpc(request_pb, retry=retry, timeout=timeout, metadata=metadata,) def cancel_operation( self, @@ -1579,9 +1585,11 @@ def cancel_operation( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.CancelOperationRequest(**request) + request_pb = operations_pb2.CancelOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.CancelOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1591,14 +1599,14 @@ def cancel_operation( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. self._validate_universe_domain() # Send the request. - rpc(request, retry=retry, timeout=timeout, metadata=metadata,) + rpc(request_pb, retry=retry, timeout=timeout, metadata=metadata,) def wait_operation( self, @@ -1635,9 +1643,11 @@ def wait_operation( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = operations_pb2.WaitOperationRequest(**request) + request_pb = operations_pb2.WaitOperationRequest() + elif isinstance(request, dict): + request_pb = operations_pb2.WaitOperationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1647,7 +1657,7 @@ def wait_operation( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. @@ -1656,7 +1666,7 @@ def wait_operation( try: # Send the request. response = rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -1693,9 +1703,11 @@ def get_location( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = locations_pb2.GetLocationRequest(**request) + request_pb = locations_pb2.GetLocationRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.GetLocationRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1705,7 +1717,7 @@ def get_location( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. @@ -1714,7 +1726,7 @@ def get_location( try: # Send the request. response = rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response @@ -1751,9 +1763,11 @@ def list_locations( # The request isn't a proto-plus wrapped type, # so it must be constructed via keyword expansion. if request is None: - request = {} - if isinstance(request, dict): - request = locations_pb2.ListLocationsRequest(**request) + request_pb = locations_pb2.ListLocationsRequest() + elif isinstance(request, dict): + request_pb = locations_pb2.ListLocationsRequest(**request) + else: + request_pb = request # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -1763,7 +1777,7 @@ def list_locations( # add these here. metadata = tuple(metadata) + ( gapic_v1.routing_header.to_grpc_metadata( - (("name", request.name),)), + (("name", request_pb.name),)), ) # Validate the universe domain. @@ -1772,7 +1786,7 @@ def list_locations( try: # Send the request. response = rpc( - request, retry=retry, timeout=timeout, metadata=metadata,) + request_pb, retry=retry, timeout=timeout, metadata=metadata,) # Done; return the response. return response From b50adfce978cd46cf13be5a3d24b38dcc443b6dc Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Tue, 20 Jan 2026 23:55:36 -0800 Subject: [PATCH 25/26] updated wrapped methods type --- .../%version/%sub/services/%service/transports/base.py.j2 | 4 +++- .../%sub/services/%service/transports/base.py.j2 | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/gapic/ads-templates/%namespace/%name/%version/%sub/services/%service/transports/base.py.j2 b/gapic/ads-templates/%namespace/%name/%version/%sub/services/%service/transports/base.py.j2 index 9cb924a529..a5a5855deb 100644 --- a/gapic/ads-templates/%namespace/%name/%version/%sub/services/%service/transports/base.py.j2 +++ b/gapic/ads-templates/%namespace/%name/%version/%sub/services/%service/transports/base.py.j2 @@ -3,7 +3,7 @@ {% block content %} import abc -from typing import Awaitable, Callable, Dict, Optional, Sequence, Union +from typing import Any, Awaitable, Callable, Dict, Optional, Sequence, Union import google.auth # type: ignore import google.api_core # type: ignore @@ -98,6 +98,8 @@ class {{ service.name }}Transport(abc.ABC): host += ':443' self._host = host + self._wrapped_methods: Dict[Callable[..., Any], Callable[..., Any]] = {} + # Save the scopes. self._scopes = scopes diff --git a/gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/base.py.j2 b/gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/base.py.j2 index 11e9e41f3a..1ea30f8e27 100644 --- a/gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/base.py.j2 +++ b/gapic/templates/%namespace/%name_%version/%sub/services/%service/transports/base.py.j2 @@ -3,7 +3,7 @@ {% block content %} import abc -from typing import Awaitable, Callable, Dict, Optional, Sequence, Union +from typing import Any, Awaitable, Callable, Dict, Optional, Sequence, Union {% set package_path = api.naming.module_namespace|join('.') + "." + api.naming.versioned_module_name %} from {{package_path}} import gapic_version as package_version @@ -143,6 +143,8 @@ class {{ service.name }}Transport(abc.ABC): host += ':443' self._host = host + self._wrapped_methods: Dict[Callable[..., Any], Callable[..., Any]] = {} + @property def host(self): return self._host From c98f2f0aeeccd39203c97546bab528d36dd02354 Mon Sep 17 00:00:00 2001 From: Daniel Sanche Date: Wed, 21 Jan 2026 01:57:27 -0800 Subject: [PATCH 26/26] updated goldens --- .../cloud/asset_v1/services/asset_service/transports/base.py | 4 +++- .../services/iam_credentials/transports/base.py | 4 +++- .../cloud/eventarc_v1/services/eventarc/transports/base.py | 4 +++- .../logging_v2/services/config_service_v2/transports/base.py | 4 +++- .../logging_v2/services/logging_service_v2/transports/base.py | 4 +++- .../logging_v2/services/metrics_service_v2/transports/base.py | 4 +++- .../logging_v2/services/config_service_v2/transports/base.py | 4 +++- .../logging_v2/services/logging_service_v2/transports/base.py | 4 +++- .../logging_v2/services/metrics_service_v2/transports/base.py | 4 +++- .../cloud/redis_v1/services/cloud_redis/transports/base.py | 4 +++- .../cloud/redis_v1/services/cloud_redis/transports/base.py | 4 +++- 11 files changed, 33 insertions(+), 11 deletions(-) diff --git a/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/transports/base.py b/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/transports/base.py index d1f8c36c11..7636515bcc 100755 --- a/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/transports/base.py +++ b/tests/integration/goldens/asset/google/cloud/asset_v1/services/asset_service/transports/base.py @@ -14,7 +14,7 @@ # limitations under the License. # import abc -from typing import Awaitable, Callable, Dict, Optional, Sequence, Union +from typing import Any, Awaitable, Callable, Dict, Optional, Sequence, Union from google.cloud.asset_v1 import gapic_version as package_version @@ -120,6 +120,8 @@ def __init__( host += ':443' self._host = host + self._wrapped_methods: Dict[Callable[..., Any], Callable[..., Any]] = {} + @property def host(self): return self._host diff --git a/tests/integration/goldens/credentials/google/iam/credentials_v1/services/iam_credentials/transports/base.py b/tests/integration/goldens/credentials/google/iam/credentials_v1/services/iam_credentials/transports/base.py index 5eca520ccd..e0c0540c08 100755 --- a/tests/integration/goldens/credentials/google/iam/credentials_v1/services/iam_credentials/transports/base.py +++ b/tests/integration/goldens/credentials/google/iam/credentials_v1/services/iam_credentials/transports/base.py @@ -14,7 +14,7 @@ # limitations under the License. # import abc -from typing import Awaitable, Callable, Dict, Optional, Sequence, Union +from typing import Any, Awaitable, Callable, Dict, Optional, Sequence, Union from google.iam.credentials_v1 import gapic_version as package_version @@ -117,6 +117,8 @@ def __init__( host += ':443' self._host = host + self._wrapped_methods: Dict[Callable[..., Any], Callable[..., Any]] = {} + @property def host(self): return self._host diff --git a/tests/integration/goldens/eventarc/google/cloud/eventarc_v1/services/eventarc/transports/base.py b/tests/integration/goldens/eventarc/google/cloud/eventarc_v1/services/eventarc/transports/base.py index 654a746911..262670647f 100755 --- a/tests/integration/goldens/eventarc/google/cloud/eventarc_v1/services/eventarc/transports/base.py +++ b/tests/integration/goldens/eventarc/google/cloud/eventarc_v1/services/eventarc/transports/base.py @@ -14,7 +14,7 @@ # limitations under the License. # import abc -from typing import Awaitable, Callable, Dict, Optional, Sequence, Union +from typing import Any, Awaitable, Callable, Dict, Optional, Sequence, Union from google.cloud.eventarc_v1 import gapic_version as package_version @@ -128,6 +128,8 @@ def __init__( host += ':443' self._host = host + self._wrapped_methods: Dict[Callable[..., Any], Callable[..., Any]] = {} + @property def host(self): return self._host diff --git a/tests/integration/goldens/logging/google/cloud/logging_v2/services/config_service_v2/transports/base.py b/tests/integration/goldens/logging/google/cloud/logging_v2/services/config_service_v2/transports/base.py index a9ce0fc3ef..8dc5c75947 100755 --- a/tests/integration/goldens/logging/google/cloud/logging_v2/services/config_service_v2/transports/base.py +++ b/tests/integration/goldens/logging/google/cloud/logging_v2/services/config_service_v2/transports/base.py @@ -14,7 +14,7 @@ # limitations under the License. # import abc -from typing import Awaitable, Callable, Dict, Optional, Sequence, Union +from typing import Any, Awaitable, Callable, Dict, Optional, Sequence, Union from google.cloud.logging_v2 import gapic_version as package_version @@ -123,6 +123,8 @@ def __init__( host += ':443' self._host = host + self._wrapped_methods: Dict[Callable[..., Any], Callable[..., Any]] = {} + @property def host(self): return self._host diff --git a/tests/integration/goldens/logging/google/cloud/logging_v2/services/logging_service_v2/transports/base.py b/tests/integration/goldens/logging/google/cloud/logging_v2/services/logging_service_v2/transports/base.py index d30a4213a5..038531b891 100755 --- a/tests/integration/goldens/logging/google/cloud/logging_v2/services/logging_service_v2/transports/base.py +++ b/tests/integration/goldens/logging/google/cloud/logging_v2/services/logging_service_v2/transports/base.py @@ -14,7 +14,7 @@ # limitations under the License. # import abc -from typing import Awaitable, Callable, Dict, Optional, Sequence, Union +from typing import Any, Awaitable, Callable, Dict, Optional, Sequence, Union from google.cloud.logging_v2 import gapic_version as package_version @@ -123,6 +123,8 @@ def __init__( host += ':443' self._host = host + self._wrapped_methods: Dict[Callable[..., Any], Callable[..., Any]] = {} + @property def host(self): return self._host diff --git a/tests/integration/goldens/logging/google/cloud/logging_v2/services/metrics_service_v2/transports/base.py b/tests/integration/goldens/logging/google/cloud/logging_v2/services/metrics_service_v2/transports/base.py index 776ba557f3..454596e3bf 100755 --- a/tests/integration/goldens/logging/google/cloud/logging_v2/services/metrics_service_v2/transports/base.py +++ b/tests/integration/goldens/logging/google/cloud/logging_v2/services/metrics_service_v2/transports/base.py @@ -14,7 +14,7 @@ # limitations under the License. # import abc -from typing import Awaitable, Callable, Dict, Optional, Sequence, Union +from typing import Any, Awaitable, Callable, Dict, Optional, Sequence, Union from google.cloud.logging_v2 import gapic_version as package_version @@ -123,6 +123,8 @@ def __init__( host += ':443' self._host = host + self._wrapped_methods: Dict[Callable[..., Any], Callable[..., Any]] = {} + @property def host(self): return self._host diff --git a/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/config_service_v2/transports/base.py b/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/config_service_v2/transports/base.py index a9ce0fc3ef..8dc5c75947 100755 --- a/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/config_service_v2/transports/base.py +++ b/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/config_service_v2/transports/base.py @@ -14,7 +14,7 @@ # limitations under the License. # import abc -from typing import Awaitable, Callable, Dict, Optional, Sequence, Union +from typing import Any, Awaitable, Callable, Dict, Optional, Sequence, Union from google.cloud.logging_v2 import gapic_version as package_version @@ -123,6 +123,8 @@ def __init__( host += ':443' self._host = host + self._wrapped_methods: Dict[Callable[..., Any], Callable[..., Any]] = {} + @property def host(self): return self._host diff --git a/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/logging_service_v2/transports/base.py b/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/logging_service_v2/transports/base.py index d30a4213a5..038531b891 100755 --- a/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/logging_service_v2/transports/base.py +++ b/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/logging_service_v2/transports/base.py @@ -14,7 +14,7 @@ # limitations under the License. # import abc -from typing import Awaitable, Callable, Dict, Optional, Sequence, Union +from typing import Any, Awaitable, Callable, Dict, Optional, Sequence, Union from google.cloud.logging_v2 import gapic_version as package_version @@ -123,6 +123,8 @@ def __init__( host += ':443' self._host = host + self._wrapped_methods: Dict[Callable[..., Any], Callable[..., Any]] = {} + @property def host(self): return self._host diff --git a/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/metrics_service_v2/transports/base.py b/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/metrics_service_v2/transports/base.py index 776ba557f3..454596e3bf 100755 --- a/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/metrics_service_v2/transports/base.py +++ b/tests/integration/goldens/logging_internal/google/cloud/logging_v2/services/metrics_service_v2/transports/base.py @@ -14,7 +14,7 @@ # limitations under the License. # import abc -from typing import Awaitable, Callable, Dict, Optional, Sequence, Union +from typing import Any, Awaitable, Callable, Dict, Optional, Sequence, Union from google.cloud.logging_v2 import gapic_version as package_version @@ -123,6 +123,8 @@ def __init__( host += ':443' self._host = host + self._wrapped_methods: Dict[Callable[..., Any], Callable[..., Any]] = {} + @property def host(self): return self._host diff --git a/tests/integration/goldens/redis/google/cloud/redis_v1/services/cloud_redis/transports/base.py b/tests/integration/goldens/redis/google/cloud/redis_v1/services/cloud_redis/transports/base.py index 54f7d694a3..78e44f7381 100755 --- a/tests/integration/goldens/redis/google/cloud/redis_v1/services/cloud_redis/transports/base.py +++ b/tests/integration/goldens/redis/google/cloud/redis_v1/services/cloud_redis/transports/base.py @@ -14,7 +14,7 @@ # limitations under the License. # import abc -from typing import Awaitable, Callable, Dict, Optional, Sequence, Union +from typing import Any, Awaitable, Callable, Dict, Optional, Sequence, Union from google.cloud.redis_v1 import gapic_version as package_version @@ -120,6 +120,8 @@ def __init__( host += ':443' self._host = host + self._wrapped_methods: Dict[Callable[..., Any], Callable[..., Any]] = {} + @property def host(self): return self._host diff --git a/tests/integration/goldens/redis_selective/google/cloud/redis_v1/services/cloud_redis/transports/base.py b/tests/integration/goldens/redis_selective/google/cloud/redis_v1/services/cloud_redis/transports/base.py index c442745a86..5ae62e8af2 100755 --- a/tests/integration/goldens/redis_selective/google/cloud/redis_v1/services/cloud_redis/transports/base.py +++ b/tests/integration/goldens/redis_selective/google/cloud/redis_v1/services/cloud_redis/transports/base.py @@ -14,7 +14,7 @@ # limitations under the License. # import abc -from typing import Awaitable, Callable, Dict, Optional, Sequence, Union +from typing import Any, Awaitable, Callable, Dict, Optional, Sequence, Union from google.cloud.redis_v1 import gapic_version as package_version @@ -120,6 +120,8 @@ def __init__( host += ':443' self._host = host + self._wrapped_methods: Dict[Callable[..., Any], Callable[..., Any]] = {} + @property def host(self): return self._host