Skip to content

Commit

Permalink
fix: use correct typing for retries
Browse files Browse the repository at this point in the history
fix: import 'ClientOptions' class correctly

Closes #1024
Closes #1025
  • Loading branch information
tseaver committed Oct 13, 2021
1 parent 206196b commit 67634ad
Show file tree
Hide file tree
Showing 17 changed files with 163 additions and 133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ 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

OptionalRetry = Union[retries.Retry, object]

{% filter sort_lines %}
{% for method in service.methods.values() %}
{% for ref_type in method.flat_ref_types %}
Expand Down Expand Up @@ -306,7 +308,7 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta):
requests: Iterator[{{ method.input.ident }}] = None,
*,
{% endif %}
retry: retries.Retry = gapic_v1.method.DEFAULT,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: float = None,
metadata: Sequence[Tuple[str, str]] = (),
{% if not method.server_streaming %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ import pkg_resources
import warnings
{% endif %}

import google.api_core.client_options as ClientOptions # type: ignore
from google.api_core.client_options import ClientOptions # type: ignore
from google.api_core import exceptions as core_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 as ga_credentials # type: ignore
from google.oauth2 import service_account # type: ignore

OptionalRetry = Union[retries.Retry, object]

{% filter sort_lines %}
{% for method in service.methods.values() %}
{% for ref_type in method.flat_ref_types %}
Expand Down Expand Up @@ -156,7 +158,7 @@ class {{ service.async_client_name }}:
requests: AsyncIterator[{{ method.input.ident }}] = None,
*,
{% endif %}
retry: retries.Retry = gapic_v1.method.DEFAULT,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: float = None,
metadata: Sequence[Tuple[str, str]] = (),
{% if not method.server_streaming %}
Expand Down Expand Up @@ -331,7 +333,7 @@ class {{ service.async_client_name }}:
self,
request: iam_policy_pb2.SetIamPolicyRequest = None,
*,
retry: retries.Retry = gapic_v1.method.DEFAULT,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: float = None,
metadata: Sequence[Tuple[str, str]] = (),
) -> policy_pb2.Policy:
Expand Down Expand Up @@ -439,7 +441,7 @@ class {{ service.async_client_name }}:
self,
request: iam_policy_pb2.GetIamPolicyRequest = None,
*,
retry: retries.Retry = gapic_v1.method.DEFAULT,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: float = None,
metadata: Sequence[Tuple[str, str]] = (),
) -> policy_pb2.Policy:
Expand Down Expand Up @@ -548,7 +550,7 @@ class {{ service.async_client_name }}:
self,
request: iam_policy_pb2.TestIamPermissionsRequest = None,
*,
retry: retries.Retry = gapic_v1.method.DEFAULT,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: float = None,
metadata: Sequence[Tuple[str, str]] = (),
) -> iam_policy_pb2.TestIamPermissionsResponse:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ 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

OptionalRetry = Union[retries.Retry, object]

{% filter sort_lines %}
{% for method in service.methods.values() %}
{% for ref_type in method.flat_ref_types %}
Expand Down Expand Up @@ -322,7 +324,7 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta):
requests: Iterator[{{ method.input.ident }}] = None,
*,
{% endif %}
retry: retries.Retry = gapic_v1.method.DEFAULT,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: float = None,
metadata: Sequence[Tuple[str, str]] = (),
{% if not method.server_streaming %}
Expand Down Expand Up @@ -495,7 +497,7 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta):
self,
request: iam_policy_pb2.SetIamPolicyRequest = None,
*,
retry: retries.Retry = gapic_v1.method.DEFAULT,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: float = None,
metadata: Sequence[Tuple[str, str]] = (),
) -> policy_pb2.Policy:
Expand Down Expand Up @@ -605,7 +607,7 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta):
self,
request: iam_policy_pb2.GetIamPolicyRequest = None,
*,
retry: retries.Retry = gapic_v1.method.DEFAULT,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: float = None,
metadata: Sequence[Tuple[str, str]] = (),
) -> policy_pb2.Policy:
Expand Down Expand Up @@ -716,7 +718,7 @@ class {{ service.client_name }}(metaclass={{ service.client_name }}Meta):
self,
request: iam_policy_pb2.TestIamPermissionsRequest = None,
*,
retry: retries.Retry = gapic_v1.method.DEFAULT,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: float = None,
metadata: Sequence[Tuple[str, str]] = (),
) -> iam_policy_pb2.TestIamPermissionsResponse:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ from google.api_core import path_template # type: ignore
from google.api_core import gapic_v1 # type: ignore
from google.api_core import operations_v1
from requests import __version__ as requests_version
from typing import Callable, Dict, Optional, Sequence, Tuple
from typing import Callable, Dict, Optional, Sequence, Tuple, Union
import warnings

OptionalRetry = Union[retries.Retry, object]
{% extends '_base.py.j2' %}

{% block content %}
Expand Down Expand Up @@ -153,7 +155,7 @@ class {{service.name}}RestTransport({{service.name}}Transport):
{%- if method.http_options and not method.lro and not (method.server_streaming or method.client_streaming) %}
def _{{method.name | snake_case}}(self,
request: {{method.input.ident}}, *,
retry: retries.Retry=gapic_v1.method.DEFAULT,
retry: OptionalRetry=gapic_v1.method.DEFAULT,
timeout: float=None,
metadata: Sequence[Tuple[str, str]]=(),
) -> {{method.output.ident}}:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@
from typing import Dict, Sequence, Tuple, Type, Union
import pkg_resources

import google.api_core.client_options as ClientOptions # type: ignore
from google.api_core.client_options import ClientOptions # type: ignore
from google.api_core import exceptions as core_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 as ga_credentials # type: ignore
from google.oauth2 import service_account # type: ignore

OptionalRetry = Union[retries.Retry, object]

from google.api_core import operation # type: ignore
from google.api_core import operation_async # type: ignore
from google.cloud.asset_v1.services.asset_service import pagers
Expand Down Expand Up @@ -153,7 +155,7 @@ def __init__(self, *,
async def export_assets(self,
request: asset_service.ExportAssetsRequest = None,
*,
retry: retries.Retry = gapic_v1.method.DEFAULT,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: float = None,
metadata: Sequence[Tuple[str, str]] = (),
) -> operation_async.AsyncOperation:
Expand Down Expand Up @@ -233,7 +235,7 @@ async def list_assets(self,
request: asset_service.ListAssetsRequest = None,
*,
parent: str = None,
retry: retries.Retry = gapic_v1.method.DEFAULT,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: float = None,
metadata: Sequence[Tuple[str, str]] = (),
) -> pagers.ListAssetsAsyncPager:
Expand Down Expand Up @@ -321,7 +323,7 @@ async def list_assets(self,
async def batch_get_assets_history(self,
request: asset_service.BatchGetAssetsHistoryRequest = None,
*,
retry: retries.Retry = gapic_v1.method.DEFAULT,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: float = None,
metadata: Sequence[Tuple[str, str]] = (),
) -> asset_service.BatchGetAssetsHistoryResponse:
Expand Down Expand Up @@ -387,7 +389,7 @@ async def create_feed(self,
request: asset_service.CreateFeedRequest = None,
*,
parent: str = None,
retry: retries.Retry = gapic_v1.method.DEFAULT,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: float = None,
metadata: Sequence[Tuple[str, str]] = (),
) -> asset_service.Feed:
Expand Down Expand Up @@ -475,7 +477,7 @@ async def get_feed(self,
request: asset_service.GetFeedRequest = None,
*,
name: str = None,
retry: retries.Retry = gapic_v1.method.DEFAULT,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: float = None,
metadata: Sequence[Tuple[str, str]] = (),
) -> asset_service.Feed:
Expand Down Expand Up @@ -563,7 +565,7 @@ async def list_feeds(self,
request: asset_service.ListFeedsRequest = None,
*,
parent: str = None,
retry: retries.Retry = gapic_v1.method.DEFAULT,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: float = None,
metadata: Sequence[Tuple[str, str]] = (),
) -> asset_service.ListFeedsResponse:
Expand Down Expand Up @@ -647,7 +649,7 @@ async def update_feed(self,
request: asset_service.UpdateFeedRequest = None,
*,
feed: asset_service.Feed = None,
retry: retries.Retry = gapic_v1.method.DEFAULT,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: float = None,
metadata: Sequence[Tuple[str, str]] = (),
) -> asset_service.Feed:
Expand Down Expand Up @@ -729,7 +731,7 @@ async def delete_feed(self,
request: asset_service.DeleteFeedRequest = None,
*,
name: str = None,
retry: retries.Retry = gapic_v1.method.DEFAULT,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: float = None,
metadata: Sequence[Tuple[str, str]] = (),
) -> None:
Expand Down Expand Up @@ -805,7 +807,7 @@ async def search_all_resources(self,
scope: str = None,
query: str = None,
asset_types: Sequence[str] = None,
retry: retries.Retry = gapic_v1.method.DEFAULT,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: float = None,
metadata: Sequence[Tuple[str, str]] = (),
) -> pagers.SearchAllResourcesAsyncPager:
Expand Down Expand Up @@ -991,7 +993,7 @@ async def search_all_iam_policies(self,
*,
scope: str = None,
query: str = None,
retry: retries.Retry = gapic_v1.method.DEFAULT,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: float = None,
metadata: Sequence[Tuple[str, str]] = (),
) -> pagers.SearchAllIamPoliciesAsyncPager:
Expand Down Expand Up @@ -1155,7 +1157,7 @@ async def search_all_iam_policies(self,
async def analyze_iam_policy(self,
request: asset_service.AnalyzeIamPolicyRequest = None,
*,
retry: retries.Retry = gapic_v1.method.DEFAULT,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: float = None,
metadata: Sequence[Tuple[str, str]] = (),
) -> asset_service.AnalyzeIamPolicyResponse:
Expand Down Expand Up @@ -1217,7 +1219,7 @@ async def analyze_iam_policy(self,
async def analyze_iam_policy_longrunning(self,
request: asset_service.AnalyzeIamPolicyLongrunningRequest = None,
*,
retry: retries.Retry = gapic_v1.method.DEFAULT,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: float = None,
metadata: Sequence[Tuple[str, str]] = (),
) -> operation_async.AsyncOperation:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
from google.auth.exceptions import MutualTLSChannelError # type: ignore
from google.oauth2 import service_account # type: ignore

OptionalRetry = Union[retries.Retry, object]

from google.api_core import operation # type: ignore
from google.api_core import operation_async # type: ignore
from google.cloud.asset_v1.services.asset_service import pagers
Expand Down Expand Up @@ -350,7 +352,7 @@ def __init__(self, *,
def export_assets(self,
request: Union[asset_service.ExportAssetsRequest, dict] = None,
*,
retry: retries.Retry = gapic_v1.method.DEFAULT,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: float = None,
metadata: Sequence[Tuple[str, str]] = (),
) -> operation.Operation:
Expand Down Expand Up @@ -431,7 +433,7 @@ def list_assets(self,
request: Union[asset_service.ListAssetsRequest, dict] = None,
*,
parent: str = None,
retry: retries.Retry = gapic_v1.method.DEFAULT,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: float = None,
metadata: Sequence[Tuple[str, str]] = (),
) -> pagers.ListAssetsPager:
Expand Down Expand Up @@ -519,7 +521,7 @@ def list_assets(self,
def batch_get_assets_history(self,
request: Union[asset_service.BatchGetAssetsHistoryRequest, dict] = None,
*,
retry: retries.Retry = gapic_v1.method.DEFAULT,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: float = None,
metadata: Sequence[Tuple[str, str]] = (),
) -> asset_service.BatchGetAssetsHistoryResponse:
Expand Down Expand Up @@ -579,7 +581,7 @@ def create_feed(self,
request: Union[asset_service.CreateFeedRequest, dict] = None,
*,
parent: str = None,
retry: retries.Retry = gapic_v1.method.DEFAULT,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: float = None,
metadata: Sequence[Tuple[str, str]] = (),
) -> asset_service.Feed:
Expand Down Expand Up @@ -667,7 +669,7 @@ def get_feed(self,
request: Union[asset_service.GetFeedRequest, dict] = None,
*,
name: str = None,
retry: retries.Retry = gapic_v1.method.DEFAULT,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: float = None,
metadata: Sequence[Tuple[str, str]] = (),
) -> asset_service.Feed:
Expand Down Expand Up @@ -748,7 +750,7 @@ def list_feeds(self,
request: Union[asset_service.ListFeedsRequest, dict] = None,
*,
parent: str = None,
retry: retries.Retry = gapic_v1.method.DEFAULT,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: float = None,
metadata: Sequence[Tuple[str, str]] = (),
) -> asset_service.ListFeedsResponse:
Expand Down Expand Up @@ -825,7 +827,7 @@ def update_feed(self,
request: Union[asset_service.UpdateFeedRequest, dict] = None,
*,
feed: asset_service.Feed = None,
retry: retries.Retry = gapic_v1.method.DEFAULT,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: float = None,
metadata: Sequence[Tuple[str, str]] = (),
) -> asset_service.Feed:
Expand Down Expand Up @@ -907,7 +909,7 @@ def delete_feed(self,
request: Union[asset_service.DeleteFeedRequest, dict] = None,
*,
name: str = None,
retry: retries.Retry = gapic_v1.method.DEFAULT,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: float = None,
metadata: Sequence[Tuple[str, str]] = (),
) -> None:
Expand Down Expand Up @@ -976,7 +978,7 @@ def search_all_resources(self,
scope: str = None,
query: str = None,
asset_types: Sequence[str] = None,
retry: retries.Retry = gapic_v1.method.DEFAULT,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: float = None,
metadata: Sequence[Tuple[str, str]] = (),
) -> pagers.SearchAllResourcesPager:
Expand Down Expand Up @@ -1155,7 +1157,7 @@ def search_all_iam_policies(self,
*,
scope: str = None,
query: str = None,
retry: retries.Retry = gapic_v1.method.DEFAULT,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: float = None,
metadata: Sequence[Tuple[str, str]] = (),
) -> pagers.SearchAllIamPoliciesPager:
Expand Down Expand Up @@ -1312,7 +1314,7 @@ def search_all_iam_policies(self,
def analyze_iam_policy(self,
request: Union[asset_service.AnalyzeIamPolicyRequest, dict] = None,
*,
retry: retries.Retry = gapic_v1.method.DEFAULT,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: float = None,
metadata: Sequence[Tuple[str, str]] = (),
) -> asset_service.AnalyzeIamPolicyResponse:
Expand Down Expand Up @@ -1369,7 +1371,7 @@ def analyze_iam_policy(self,
def analyze_iam_policy_longrunning(self,
request: Union[asset_service.AnalyzeIamPolicyLongrunningRequest, dict] = None,
*,
retry: retries.Retry = gapic_v1.method.DEFAULT,
retry: OptionalRetry = gapic_v1.method.DEFAULT,
timeout: float = None,
metadata: Sequence[Tuple[str, str]] = (),
) -> operation.Operation:
Expand Down
Loading

0 comments on commit 67634ad

Please sign in to comment.