Skip to content
This repository was archived by the owner on Mar 26, 2026. It is now read-only.

Commit d0731a5

Browse files
authored
Merge branch 'master' into fix-exceptions-port
2 parents 67e456e + 29c201b commit d0731a5

5 files changed

Lines changed: 107 additions & 76 deletions

File tree

gapic/generator/generator.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def get_response(
8989
sample_templates, client_templates = utils.partition(
9090
lambda fname: os.path.basename(
9191
fname) == samplegen.DEFAULT_TEMPLATE_NAME,
92-
self._env.loader.list_templates(),
92+
self._env.loader.list_templates(), # type: ignore
9393
)
9494

9595
# Iterate over each template and add the appropriate output files
@@ -113,7 +113,7 @@ def get_response(
113113
sample_output = self._generate_samples_and_manifest(
114114
api_schema, self._env.get_template(sample_templates[0]),
115115
opts=opts,
116-
)
116+
)
117117
output_files.update(sample_output)
118118

119119
# Return the CodeGeneratorResponse output.
@@ -286,10 +286,10 @@ def _render_template(
286286
for service in api_schema.services.values():
287287
if (
288288
(skip_subpackages
289-
and service.meta.address.subpackage != api_schema.subpackage_view)
289+
and service.meta.address.subpackage != api_schema.subpackage_view)
290290
or
291291
('transport' in template_name
292-
and not self._is_desired_transport(template_name, opts))
292+
and not self._is_desired_transport(template_name, opts))
293293
or
294294
# TODO(yon-mg) - remove when rest async implementation resolved
295295
# temporarily stop async client gen while rest async is unkown

gapic/templates/%namespace/%name_%version/%sub/services/%service/async_client.py.j2

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{% extends '_base.py.j2' %}
1+
{% extends "_base.py.j2" %}
22

33
{% block content %}
44

@@ -51,7 +51,8 @@ class {{ service.async_client_name }}:
5151

5252
@classmethod
5353
def from_service_account_info(cls, info: dict, *args, **kwargs):
54-
"""Creates an instance of this client using the provided credentials info.
54+
"""Creates an instance of this client using the provided credentials
55+
info.
5556

5657
Args:
5758
info (dict): The service account private key info.
@@ -66,7 +67,7 @@ class {{ service.async_client_name }}:
6667
@classmethod
6768
def from_service_account_file(cls, filename: str, *args, **kwargs):
6869
"""Creates an instance of this client using the provided credentials
69-
file.
70+
file.
7071

7172
Args:
7273
filename (str): The path to the service account private key json
@@ -83,7 +84,7 @@ class {{ service.async_client_name }}:
8384

8485
@property
8586
def transport(self) -> {{ service.name }}Transport:
86-
"""Return the transport used by the client instance.
87+
"""Returns the transport used by the client instance.
8788

8889
Returns:
8990
{{ service.name }}Transport: The transport used by the client instance.
@@ -95,11 +96,11 @@ class {{ service.async_client_name }}:
9596

9697
def __init__(self, *,
9798
credentials: ga_credentials.Credentials = None,
98-
transport: Union[str, {{ service.name }}Transport] = 'grpc_asyncio',
99+
transport: Union[str, {{ service.name }}Transport] = "grpc_asyncio",
99100
client_options: ClientOptions = None,
100101
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
101102
) -> None:
102-
"""Instantiate the {{ (service.client_name|snake_case).replace('_', ' ') }}.
103+
"""Instantiates the {{ (service.client_name|snake_case).replace("_", " ") }}.
103104

104105
Args:
105106
credentials (Optional[google.auth.credentials.Credentials]): The
@@ -165,7 +166,7 @@ class {{ service.async_client_name }}:
165166
Args:
166167
{% if not method.client_streaming %}
167168
request (:class:`{{ method.input.ident.sphinx }}`):
168-
The request object.{{ ' ' }}
169+
The request object.{{ " " }}
169170
{{- method.input.meta.doc|wrap(width=72, offset=36, indent=16) }}
170171
{% for key, field in method.flattened_fields.items() %}
171172
{{ field.name }} (:class:`{{ field.ident.sphinx }}`):
@@ -176,7 +177,7 @@ class {{ service.async_client_name }}:
176177
{% endfor %}
177178
{% else %}
178179
requests (AsyncIterator[`{{ method.input.ident.sphinx }}`]):
179-
The request object AsyncIterator.{{ ' ' }}
180+
The request object AsyncIterator.{{ " " }}
180181
{{- method.input.meta.doc|wrap(width=72, offset=36, indent=16) }}
181182
{% endif %}
182183
retry (google.api_core.retry.Retry): Designation of what errors, if any,
@@ -200,10 +201,10 @@ class {{ service.async_client_name }}:
200201
{% if method.flattened_fields %}
201202
# Sanity check: If we got a request object, we should *not* have
202203
# gotten any keyword arguments that map to the request.
203-
has_flattened_params = any([{{ method.flattened_fields.values()|join(', ', attribute='name') }}])
204+
has_flattened_params = any([{{ method.flattened_fields.values()|join(", ", attribute="name") }}])
204205
if request is not None and has_flattened_params:
205-
raise ValueError('If the `request` argument is set, then none of '
206-
'the individual field arguments should be set.')
206+
raise ValueError("If the `request` argument is set, then none of "
207+
"the individual field arguments should be set.")
207208

208209
{% endif %}
209210
{% if method.input.ident.package != method.ident.package %} {# request lives in a different package, so there is no proto wrapper #}
@@ -251,7 +252,7 @@ class {{ service.async_client_name }}:
251252
{% if method.retry.max_backoff %}maximum={{ method.retry.max_backoff }},{% endif %}
252253
{% if method.retry.backoff_multiplier %}multiplier={{ method.retry.backoff_multiplier }},{% endif %}
253254
predicate=retries.if_exception_type(
254-
{% for ex in method.retry.retryable_exceptions|sort(attribute='__name__') %}
255+
{% for ex in method.retry.retryable_exceptions|sort(attribute="__name__") %}
255256
core_exceptions.{{ ex.__name__ }},
256257
{% endfor %}
257258
),
@@ -269,7 +270,7 @@ class {{ service.async_client_name }}:
269270
gapic_v1.routing_header.to_grpc_metadata((
270271
{% for field_header in method.field_headers %}
271272
{% if not method.client_streaming %}
272-
('{{ field_header }}', request.{{ field_header }}),
273+
("{{ field_header }}", request.{{ field_header }}),
273274
{% endif %}
274275
{% endfor %}
275276
)),
@@ -313,7 +314,7 @@ class {{ service.async_client_name }}:
313314
# Done; return the response.
314315
return response
315316
{% endif %}
316-
{{ '\n' }}
317+
{{ "\n" }}
317318
{% endfor %}
318319

319320

@@ -326,8 +327,10 @@ class {{ service.async_client_name }}:
326327
timeout: float = None,
327328
metadata: Sequence[Tuple[str, str]] = (),
328329
) -> policy_pb2.Policy:
329-
r"""Sets the IAM access control policy on the specified
330-
function. Replaces any existing policy.
330+
r"""Sets the IAM access control policy on the specified function.
331+
332+
Replaces any existing policy.
333+
331334
Args:
332335
request (:class:`~.policy_pb2.SetIamPolicyRequest`):
333336
The request object. Request message for `SetIamPolicy`
@@ -433,8 +436,10 @@ class {{ service.async_client_name }}:
433436
metadata: Sequence[Tuple[str, str]] = (),
434437
) -> policy_pb2.Policy:
435438
r"""Gets the IAM access control policy for a function.
439+
436440
Returns an empty policy if the function exists and does
437441
not have a policy set.
442+
438443
Args:
439444
request (:class:`~.iam_policy_pb2.GetIamPolicyRequest`):
440445
The request object. Request message for `GetIamPolicy`
@@ -540,8 +545,11 @@ class {{ service.async_client_name }}:
540545
metadata: Sequence[Tuple[str, str]] = (),
541546
) -> iam_policy_pb2.TestIamPermissionsResponse:
542547
r"""Tests the specified permissions against the IAM access control
543-
policy for a function. If the function does not exist, this will
548+
policy for a function.
549+
550+
If the function does not exist, this will
544551
return an empty set of permissions, not a NOT_FOUND error.
552+
545553
Args:
546554
request (:class:`~.iam_policy_pb2.TestIamPermissionsRequest`):
547555
The request object. Request message for
@@ -586,14 +594,14 @@ class {{ service.async_client_name }}:
586594
try:
587595
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo(
588596
gapic_version=pkg_resources.get_distribution(
589-
'{{ api.naming.warehouse_package_name }}',
597+
"{{ api.naming.warehouse_package_name }}",
590598
).version,
591599
)
592600
except pkg_resources.DistributionNotFound:
593601
DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo()
594602

595603

596604
__all__ = (
597-
'{{ service.async_client_name }}',
605+
"{{ service.async_client_name }}",
598606
)
599607
{% endblock %}

0 commit comments

Comments
 (0)