Skip to content

chore: blacken #206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 2 additions & 12 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,13 +313,7 @@
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(
master_doc,
"google-api-core",
u"google-api-core Documentation",
[author],
1,
)
(master_doc, "google-api-core", u"google-api-core Documentation", [author], 1,)
]

# If true, show URL addresses after external links.
Expand Down Expand Up @@ -360,14 +354,10 @@
intersphinx_mapping = {
"python": ("https://python.readthedocs.org/en/latest/", None),
"google-auth": ("https://googleapis.dev/python/google-auth/latest/", None),
"google.api_core": (
"https://googleapis.dev/python/google-api-core/latest/",
None,
),
"google.api_core": ("https://googleapis.dev/python/google-api-core/latest/", None,),
"grpc": ("https://grpc.github.io/grpc/python/", None),
"proto-plus": ("https://proto-plus-python.readthedocs.io/en/latest/", None),
"protobuf": ("https://googleapis.dev/python/protobuf/latest/", None),

}


Expand Down
5 changes: 4 additions & 1 deletion google/api_core/future/async_future.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

class _OperationNotComplete(Exception):
"""Private exception used for polling via retry."""

pass


Expand Down Expand Up @@ -145,7 +146,9 @@ def add_done_callback(self, fn):
is complete.
"""
if self._background_task is None:
self._background_task = asyncio.get_event_loop().create_task(self._blocking_poll())
self._background_task = asyncio.get_event_loop().create_task(
self._blocking_poll()
)
self._future.add_done_callback(fn)

def set_result(self, result):
Expand Down
1 change: 1 addition & 0 deletions google/api_core/gapic_v1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@
if sys.version_info >= (3, 6):
from google.api_core.gapic_v1 import config_async # noqa: F401
from google.api_core.gapic_v1 import method_async # noqa: F401

__all__.append("config_async")
__all__.append("method_async")
4 changes: 3 additions & 1 deletion google/api_core/gapic_v1/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,9 @@ def parse_method_configs(interface_config, retry_impl=retry.Retry):
if retry_params_name is not None:
retry_params = retry_params_map[retry_params_name]
retry_ = _retry_from_retry_config(
retry_params, retry_codes_map[method_params["retry_codes_name"]], retry_impl
retry_params,
retry_codes_map[method_params["retry_codes_name"]],
retry_impl,
)
timeout_ = _timeout_from_retry_config(retry_params)

Expand Down
4 changes: 2 additions & 2 deletions google/api_core/gapic_v1/config_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ def parse_method_configs(interface_config):
configuration.
"""
return config.parse_method_configs(
interface_config,
retry_impl=retry_async.AsyncRetry)
interface_config, retry_impl=retry_async.AsyncRetry
)
19 changes: 10 additions & 9 deletions google/api_core/gapic_v1/method_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@

from google.api_core import general_helpers, grpc_helpers_async
from google.api_core.gapic_v1 import client_info
from google.api_core.gapic_v1.method import (_GapicCallable, # noqa: F401
DEFAULT,
USE_DEFAULT_METADATA)
from google.api_core.gapic_v1.method import _GapicCallable
from google.api_core.gapic_v1.method import DEFAULT # noqa: F401
from google.api_core.gapic_v1.method import USE_DEFAULT_METADATA # noqa: F401


def wrap_method(
func,
default_retry=None,
default_timeout=None,
client_info=client_info.DEFAULT_CLIENT_INFO,
func,
default_retry=None,
default_timeout=None,
client_info=client_info.DEFAULT_CLIENT_INFO,
):
"""Wrap an async RPC method with common behavior.

Expand All @@ -41,5 +41,6 @@ def wrap_method(

metadata = [client_info.to_grpc_metadata()] if client_info is not None else None

return general_helpers.wraps(func)(_GapicCallable(
func, default_retry, default_timeout, metadata=metadata))
return general_helpers.wraps(func)(
_GapicCallable(func, default_retry, default_timeout, metadata=metadata)
)
58 changes: 30 additions & 28 deletions google/api_core/grpc_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@ def error_remapped_callable(*args, **kwargs):
# hidden flag to see if pre-fetching is disabled.
# https://github.com/googleapis/python-pubsub/issues/93#issuecomment-630762257
prefetch_first = getattr(callable_, "_prefetch_first_result_", True)
return _StreamingResponseIterator(result, prefetch_first_result=prefetch_first)
return _StreamingResponseIterator(
result, prefetch_first_result=prefetch_first
)
except grpc.RpcError as exc:
six.raise_from(exceptions.from_grpc_error(exc), exc)

Expand Down Expand Up @@ -187,13 +189,14 @@ def wrap_errors(callable_):


def _create_composite_credentials(
credentials=None,
credentials_file=None,
default_scopes=None,
scopes=None,
ssl_credentials=None,
quota_project_id=None,
default_host=None):
credentials=None,
credentials_file=None,
default_scopes=None,
scopes=None,
ssl_credentials=None,
quota_project_id=None,
default_host=None,
):
"""Create the composite credentials for secure channels.

Args:
Expand Down Expand Up @@ -227,20 +230,20 @@ def _create_composite_credentials(

if credentials_file:
credentials, _ = google.auth.load_credentials_from_file(
credentials_file,
scopes=scopes,
default_scopes=default_scopes
credentials_file, scopes=scopes, default_scopes=default_scopes
)
elif credentials:
credentials = google.auth.credentials.with_scopes_if_required(
credentials,
scopes=scopes,
default_scopes=default_scopes
credentials, scopes=scopes, default_scopes=default_scopes
)
else:
credentials, _ = google.auth.default(scopes=scopes, default_scopes=default_scopes)
credentials, _ = google.auth.default(
scopes=scopes, default_scopes=default_scopes
)

if quota_project_id and isinstance(credentials, google.auth.credentials.CredentialsWithQuotaProject):
if quota_project_id and isinstance(
credentials, google.auth.credentials.CredentialsWithQuotaProject
):
credentials = credentials.with_quota_project(quota_project_id)

request = google.auth.transport.requests.Request()
Expand All @@ -257,21 +260,20 @@ def _create_composite_credentials(
ssl_credentials = grpc.ssl_channel_credentials()

# Combine the ssl credentials and the authorization credentials.
return grpc.composite_channel_credentials(
ssl_credentials, google_auth_credentials
)
return grpc.composite_channel_credentials(ssl_credentials, google_auth_credentials)


def create_channel(
target,
credentials=None,
scopes=None,
ssl_credentials=None,
credentials_file=None,
quota_project_id=None,
default_scopes=None,
default_host=None,
**kwargs):
target,
credentials=None,
scopes=None,
ssl_credentials=None,
credentials_file=None,
quota_project_id=None,
default_scopes=None,
default_host=None,
**kwargs
):
"""Create a secure channel with credentials.

Args:
Expand Down
35 changes: 18 additions & 17 deletions google/api_core/grpc_helpers_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@


class _WrappedCall(aio.Call):

def __init__(self):
self._call = None

Expand Down Expand Up @@ -80,7 +79,6 @@ async def wait_for_connection(self):


class _WrappedUnaryResponseMixin(_WrappedCall):

def __await__(self):
try:
response = yield from self._call.__await__()
Expand All @@ -90,7 +88,6 @@ def __await__(self):


class _WrappedStreamResponseMixin(_WrappedCall):

def __init__(self):
self._wrapped_async_generator = None

Expand All @@ -117,7 +114,6 @@ def __aiter__(self):


class _WrappedStreamRequestMixin(_WrappedCall):

async def write(self, request):
try:
await self._call.write(request)
Expand All @@ -142,11 +138,15 @@ class _WrappedUnaryStreamCall(_WrappedStreamResponseMixin, aio.UnaryStreamCall):
"""Wrapped UnaryStreamCall to map exceptions."""


class _WrappedStreamUnaryCall(_WrappedUnaryResponseMixin, _WrappedStreamRequestMixin, aio.StreamUnaryCall):
class _WrappedStreamUnaryCall(
_WrappedUnaryResponseMixin, _WrappedStreamRequestMixin, aio.StreamUnaryCall
):
"""Wrapped StreamUnaryCall to map exceptions."""


class _WrappedStreamStreamCall(_WrappedStreamRequestMixin, _WrappedStreamResponseMixin, aio.StreamStreamCall):
class _WrappedStreamStreamCall(
_WrappedStreamRequestMixin, _WrappedStreamResponseMixin, aio.StreamStreamCall
):
"""Wrapped StreamStreamCall to map exceptions."""


Expand Down Expand Up @@ -177,7 +177,7 @@ async def error_remapped_callable(*args, **kwargs):
elif isinstance(call, aio.StreamStreamCall):
call = _WrappedStreamStreamCall().with_call(call)
else:
raise TypeError('Unexpected type of call %s' % type(call))
raise TypeError("Unexpected type of call %s" % type(call))

await call.wait_for_connection()
return call
Expand Down Expand Up @@ -207,15 +207,16 @@ def wrap_errors(callable_):


def create_channel(
target,
credentials=None,
scopes=None,
ssl_credentials=None,
credentials_file=None,
quota_project_id=None,
default_scopes=None,
default_host=None,
**kwargs):
target,
credentials=None,
scopes=None,
ssl_credentials=None,
credentials_file=None,
quota_project_id=None,
default_scopes=None,
default_host=None,
**kwargs
):
"""Create an AsyncIO secure channel with credentials.

Args:
Expand Down Expand Up @@ -251,7 +252,7 @@ def create_channel(
default_scopes=default_scopes,
ssl_credentials=ssl_credentials,
quota_project_id=quota_project_id,
default_host=default_host
default_host=default_host,
)

return aio.secure_channel(target, composite_credentials, **kwargs)
Expand Down
5 changes: 1 addition & 4 deletions google/api_core/iam.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,10 +450,7 @@ def to_api_repr(self):
for binding in self._bindings:
members = binding.get("members")
if members:
new_binding = {
"role": binding["role"],
"members": sorted(members)
}
new_binding = {"role": binding["role"], "members": sorted(members)}
condition = binding.get("condition")
if condition:
new_binding["condition"] = condition
Expand Down
16 changes: 12 additions & 4 deletions google/api_core/operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,12 @@ def from_grpc(operation, operations_stub, result_type, grpc_metadata=None, **kwa
~.api_core.operation.Operation: The operation future to track the given
operation.
"""
refresh = functools.partial(_refresh_grpc, operations_stub, operation.name, metadata=grpc_metadata)
cancel = functools.partial(_cancel_grpc, operations_stub, operation.name, metadata=grpc_metadata)
refresh = functools.partial(
_refresh_grpc, operations_stub, operation.name, metadata=grpc_metadata
)
cancel = functools.partial(
_cancel_grpc, operations_stub, operation.name, metadata=grpc_metadata
)
return Operation(operation, refresh, cancel, result_type, **kwargs)


Expand All @@ -338,6 +342,10 @@ def from_gapic(operation, operations_client, result_type, grpc_metadata=None, **
~.api_core.operation.Operation: The operation future to track the given
operation.
"""
refresh = functools.partial(operations_client.get_operation, operation.name, metadata=grpc_metadata)
cancel = functools.partial(operations_client.cancel_operation, operation.name, metadata=grpc_metadata)
refresh = functools.partial(
operations_client.get_operation, operation.name, metadata=grpc_metadata
)
cancel = functools.partial(
operations_client.cancel_operation, operation.name, metadata=grpc_metadata
)
return Operation(operation, refresh, cancel, result_type, **kwargs)
8 changes: 6 additions & 2 deletions google/api_core/operation_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,10 @@ def from_gapic(operation, operations_client, result_type, grpc_metadata=None, **
~.api_core.operation.Operation: The operation future to track the given
operation.
"""
refresh = functools.partial(operations_client.get_operation, operation.name, metadata=grpc_metadata)
cancel = functools.partial(operations_client.cancel_operation, operation.name, metadata=grpc_metadata)
refresh = functools.partial(
operations_client.get_operation, operation.name, metadata=grpc_metadata
)
cancel = functools.partial(
operations_client.cancel_operation, operation.name, metadata=grpc_metadata
)
return AsyncOperation(operation, refresh, cancel, result_type, **kwargs)
16 changes: 12 additions & 4 deletions google/api_core/operations_v1/operations_async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ async def get_operation(
metadata = metadata or []
metadata.append(gapic_v1.routing_header.to_grpc_metadata({"name": name}))

return await self._get_operation(request, retry=retry, timeout=timeout, metadata=metadata)
return await self._get_operation(
request, retry=retry, timeout=timeout, metadata=metadata
)

async def list_operations(
self,
Expand Down Expand Up @@ -192,7 +194,9 @@ async def list_operations(
metadata.append(gapic_v1.routing_header.to_grpc_metadata({"name": name}))

# Create the method used to fetch pages
method = functools.partial(self._list_operations, retry=retry, timeout=timeout, metadata=metadata)
method = functools.partial(
self._list_operations, retry=retry, timeout=timeout, metadata=metadata
)

iterator = page_iterator_async.AsyncGRPCIterator(
client=None,
Expand Down Expand Up @@ -260,7 +264,9 @@ async def cancel_operation(
metadata = metadata or []
metadata.append(gapic_v1.routing_header.to_grpc_metadata({"name": name}))

await self._cancel_operation(request, retry=retry, timeout=timeout, metadata=metadata)
await self._cancel_operation(
request, retry=retry, timeout=timeout, metadata=metadata
)

async def delete_operation(
self,
Expand Down Expand Up @@ -311,4 +317,6 @@ async def delete_operation(
metadata = metadata or []
metadata.append(gapic_v1.routing_header.to_grpc_metadata({"name": name}))

await self._delete_operation(request, retry=retry, timeout=timeout, metadata=metadata)
await self._delete_operation(
request, retry=retry, timeout=timeout, metadata=metadata
)
Loading