From 629d95b74a313cb3e77c1c761ed4b64e2d604065 Mon Sep 17 00:00:00 2001 From: dpcollins-google <40498610+dpcollins-google@users.noreply.github.com> Date: Mon, 14 Sep 2020 15:11:06 -0400 Subject: [PATCH 1/4] fix: Fix client template type hints --- .../%sub/services/%service/client.py.j2 | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 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 dbd5adb522..dfbc7ff048 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 @@ -5,10 +5,10 @@ from collections import OrderedDict from distutils import util import os import re -from typing import Callable, Dict, {% if service.any_server_streaming %}Iterable, {% endif %}{% if service.any_client_streaming %}Iterator, {% endif %}Sequence, Tuple, Type, Union +from typing import Callable, Dict, Optional, {% if service.any_server_streaming %}Iterable, {% endif %}{% if service.any_client_streaming %}Iterator, {% endif %}Sequence, Tuple, Type, Union import pkg_resources -import google.api_core.client_options as ClientOptions # type: ignore +from google.api_core import client_options from google.api_core import exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore @@ -140,9 +140,9 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta): {% endfor %} def __init__(self, *, - credentials: credentials.Credentials = None, - transport: Union[str, {{ service.name }}Transport] = None, - client_options: ClientOptions = None, + credentials: Optional[credentials.Credentials] = None, + transport: Union[str, {{ service.name }}Transport, None] = None, + client_options: Optional[client_options.ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: """Instantiate the {{ (service.client_name|snake_case).replace('_', ' ') }}. @@ -156,8 +156,8 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta): transport (Union[str, ~.{{ service.name }}Transport]): The transport to use. If set to None, a transport is chosen automatically. - client_options (ClientOptions): Custom options for the client. It - won't take effect if a ``transport`` instance is provided. + client_options (client_options.ClientOptions): Custom options for the + client. It won't take effect if a ``transport`` instance is provided. (1) The ``api_endpoint`` property can be used to override the default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT environment variable can also be used to override the endpoint: @@ -183,9 +183,9 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta): creation failed for any reason. """ if isinstance(client_options, dict): - client_options = ClientOptions.from_dict(client_options) + client_options = client_options.from_dict(client_options) if client_options is None: - client_options = ClientOptions.ClientOptions() + client_options = client_options.ClientOptions() # Create SSL credentials for mutual TLS if needed. use_client_cert = bool(util.strtobool(os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false"))) From 68884e0211911884b92d6df8d4f41f22681a6762 Mon Sep 17 00:00:00 2001 From: dpcollins-google <40498610+dpcollins-google@users.noreply.github.com> Date: Mon, 14 Sep 2020 15:17:25 -0400 Subject: [PATCH 2/4] Make name not alias parameter name. --- .../%name_%version/%sub/services/%service/client.py.j2 | 10 +++++----- 1 file changed, 5 insertions(+), 5 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 dfbc7ff048..1903930c7d 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 @@ -8,7 +8,7 @@ import re from typing import Callable, Dict, Optional, {% if service.any_server_streaming %}Iterable, {% endif %}{% if service.any_client_streaming %}Iterator, {% endif %}Sequence, Tuple, Type, Union import pkg_resources -from google.api_core import client_options +from google.api_core import client_options as client_options_lib from google.api_core import exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore @@ -142,7 +142,7 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta): def __init__(self, *, credentials: Optional[credentials.Credentials] = None, transport: Union[str, {{ service.name }}Transport, None] = None, - client_options: Optional[client_options.ClientOptions] = None, + client_options: Optional[client_options_lib.ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: """Instantiate the {{ (service.client_name|snake_case).replace('_', ' ') }}. @@ -156,7 +156,7 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta): transport (Union[str, ~.{{ service.name }}Transport]): The transport to use. If set to None, a transport is chosen automatically. - client_options (client_options.ClientOptions): Custom options for the + client_options (client_options_lib.ClientOptions): Custom options for the client. It won't take effect if a ``transport`` instance is provided. (1) The ``api_endpoint`` property can be used to override the default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT @@ -183,9 +183,9 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta): creation failed for any reason. """ if isinstance(client_options, dict): - client_options = client_options.from_dict(client_options) + client_options = client_options_lib.from_dict(client_options) if client_options is None: - client_options = client_options.ClientOptions() + client_options = client_options_lib.ClientOptions() # Create SSL credentials for mutual TLS if needed. use_client_cert = bool(util.strtobool(os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false"))) From f945304f53363e25fba8a9c36063c48ab499230e Mon Sep 17 00:00:00 2001 From: dpcollins-google <40498610+dpcollins-google@users.noreply.github.com> Date: Mon, 14 Sep 2020 15:20:57 -0400 Subject: [PATCH 3/4] Update client.py.j2 --- .../%sub/services/%service/client.py.j2 | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 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 1903930c7d..b598ac2526 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 @@ -8,15 +8,15 @@ import re from typing import Callable, Dict, Optional, {% if service.any_server_streaming %}Iterable, {% endif %}{% if service.any_client_streaming %}Iterator, {% endif %}Sequence, Tuple, Type, Union import pkg_resources -from google.api_core import client_options as client_options_lib -from google.api_core import exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore -from google.auth import credentials # type: ignore -from google.auth.transport import mtls # type: ignore -from google.auth.transport.grpc import SslCredentials # type: ignore -from google.auth.exceptions import MutualTLSChannelError # type: ignore -from google.oauth2 import service_account # type: ignore +from google.api_core import client_options as client_options_lib # type: ignore +from google.api_core import exceptions # type: ignore +from google.api_core import gapic_v1 # type: ignore +from google.api_core import retry as retries # type: ignore +from google.auth import credentials # type: ignore +from google.auth.transport import mtls # type: ignore +from google.auth.transport.grpc import SslCredentials # type: ignore +from google.auth.exceptions import MutualTLSChannelError # type: ignore +from google.oauth2 import service_account # type: ignore {% filter sort_lines -%} {% for method in service.methods.values() -%} From 97854807a245b189f441a747c3933f5abfa21df5 Mon Sep 17 00:00:00 2001 From: dpcollins-google <40498610+dpcollins-google@users.noreply.github.com> Date: Tue, 15 Sep 2020 08:40:01 -0400 Subject: [PATCH 4/4] Update client.py.j2 --- .../%sub/services/%service/client.py.j2 | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 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 89322d3e37..8de258d60b 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 @@ -5,18 +5,18 @@ from collections import OrderedDict from distutils import util import os import re -from typing import Callable, Dict, {% if service.any_server_streaming %}Iterable, {% endif %}{% if service.any_client_streaming %}Iterator, {% endif %}Sequence, Tuple, Type, Union +from typing import Callable, Dict, Optional, {% if service.any_server_streaming %}Iterable, {% endif %}{% if service.any_client_streaming %}Iterator, {% endif %}Sequence, Tuple, Type, Union import pkg_resources -import google.api_core.client_options as ClientOptions # type: ignore -from google.api_core import exceptions # type: ignore -from google.api_core import gapic_v1 # type: ignore -from google.api_core import retry as retries # type: ignore -from google.auth import credentials # type: ignore -from google.auth.transport import mtls # type: ignore -from google.auth.transport.grpc import SslCredentials # type: ignore -from google.auth.exceptions import MutualTLSChannelError # type: ignore -from google.oauth2 import service_account # type: ignore +from google.api_core import client_options as client_options_lib # type: ignore +from google.api_core import exceptions # type: ignore +from google.api_core import gapic_v1 # type: ignore +from google.api_core import retry as retries # type: ignore +from google.auth import credentials # type: ignore +from google.auth.transport import mtls # type: ignore +from google.auth.transport.grpc import SslCredentials # type: ignore +from google.auth.exceptions import MutualTLSChannelError # type: ignore +from google.oauth2 import service_account # type: ignore {% filter sort_lines -%} {% for method in service.methods.values() -%} @@ -134,9 +134,9 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta): {% endfor %} def __init__(self, *, - credentials: credentials.Credentials = None, - transport: Union[str, {{ service.name }}Transport] = None, - client_options: ClientOptions = None, + credentials: Optional[credentials.Credentials] = None, + transport: Union[str, {{ service.name }}Transport, None] = None, + client_options: Optional[client_options_lib.ClientOptions] = None, client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO, ) -> None: """Instantiate the {{ (service.client_name|snake_case).replace('_', ' ') }}. @@ -150,8 +150,8 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta): transport (Union[str, ~.{{ service.name }}Transport]): The transport to use. If set to None, a transport is chosen automatically. - client_options (ClientOptions): Custom options for the client. It - won't take effect unless ``transport`` is None. + client_options (client_options_lib.ClientOptions): Custom options for the + client. It won't take effect if a ``transport`` instance is provided. (1) The ``api_endpoint`` property can be used to override the default endpoint provided by the client. GOOGLE_API_USE_MTLS_ENDPOINT environment variable can also be used to override the endpoint: @@ -171,19 +171,19 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta): API requests. If ``None``, then default info will be used. Generally, you only need to set this if you're developing your own client library. - + Raises: google.auth.exceptions.MutualTLSChannelError: If mutual TLS transport creation failed for any reason. """ if isinstance(client_options, dict): - client_options = ClientOptions.from_dict(client_options) + client_options = client_options_lib.from_dict(client_options) if client_options is None: - client_options = ClientOptions.ClientOptions() + client_options = client_options_lib.ClientOptions() # Create SSL credentials for mutual TLS if needed. use_client_cert = bool(util.strtobool(os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE", "false"))) - + ssl_credentials = None is_mtls = False if use_client_cert: