Skip to content

Commit fbf447c

Browse files
authored
chore: blacken (#206)
Also, fix 2.7 tests broken by release of 'googleapis-common-protos 1.53.0', which dropped Python 2.7 support. Closes #169
1 parent 11032cf commit fbf447c

33 files changed

+404
-260
lines changed

docs/conf.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -313,13 +313,7 @@
313313
# One entry per manual page. List of tuples
314314
# (source start file, name, description, authors, manual section).
315315
man_pages = [
316-
(
317-
master_doc,
318-
"google-api-core",
319-
u"google-api-core Documentation",
320-
[author],
321-
1,
322-
)
316+
(master_doc, "google-api-core", u"google-api-core Documentation", [author], 1,)
323317
]
324318

325319
# If true, show URL addresses after external links.
@@ -360,14 +354,10 @@
360354
intersphinx_mapping = {
361355
"python": ("https://python.readthedocs.org/en/latest/", None),
362356
"google-auth": ("https://googleapis.dev/python/google-auth/latest/", None),
363-
"google.api_core": (
364-
"https://googleapis.dev/python/google-api-core/latest/",
365-
None,
366-
),
357+
"google.api_core": ("https://googleapis.dev/python/google-api-core/latest/", None,),
367358
"grpc": ("https://grpc.github.io/grpc/python/", None),
368359
"proto-plus": ("https://proto-plus-python.readthedocs.io/en/latest/", None),
369360
"protobuf": ("https://googleapis.dev/python/protobuf/latest/", None),
370-
371361
}
372362

373363

google/api_core/future/async_future.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
class _OperationNotComplete(Exception):
2626
"""Private exception used for polling via retry."""
27+
2728
pass
2829

2930

@@ -145,7 +146,9 @@ def add_done_callback(self, fn):
145146
is complete.
146147
"""
147148
if self._background_task is None:
148-
self._background_task = asyncio.get_event_loop().create_task(self._blocking_poll())
149+
self._background_task = asyncio.get_event_loop().create_task(
150+
self._blocking_poll()
151+
)
149152
self._future.add_done_callback(fn)
150153

151154
def set_result(self, result):

google/api_core/gapic_v1/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,6 @@
2424
if sys.version_info >= (3, 6):
2525
from google.api_core.gapic_v1 import config_async # noqa: F401
2626
from google.api_core.gapic_v1 import method_async # noqa: F401
27+
2728
__all__.append("config_async")
2829
__all__.append("method_async")

google/api_core/gapic_v1/config.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,9 @@ def parse_method_configs(interface_config, retry_impl=retry.Retry):
153153
if retry_params_name is not None:
154154
retry_params = retry_params_map[retry_params_name]
155155
retry_ = _retry_from_retry_config(
156-
retry_params, retry_codes_map[method_params["retry_codes_name"]], retry_impl
156+
retry_params,
157+
retry_codes_map[method_params["retry_codes_name"]],
158+
retry_impl,
157159
)
158160
timeout_ = _timeout_from_retry_config(retry_params)
159161

google/api_core/gapic_v1/config_async.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,5 @@ def parse_method_configs(interface_config):
3838
configuration.
3939
"""
4040
return config.parse_method_configs(
41-
interface_config,
42-
retry_impl=retry_async.AsyncRetry)
41+
interface_config, retry_impl=retry_async.AsyncRetry
42+
)

google/api_core/gapic_v1/method_async.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@
1919

2020
from google.api_core import general_helpers, grpc_helpers_async
2121
from google.api_core.gapic_v1 import client_info
22-
from google.api_core.gapic_v1.method import (_GapicCallable, # noqa: F401
23-
DEFAULT,
24-
USE_DEFAULT_METADATA)
22+
from google.api_core.gapic_v1.method import _GapicCallable
23+
from google.api_core.gapic_v1.method import DEFAULT # noqa: F401
24+
from google.api_core.gapic_v1.method import USE_DEFAULT_METADATA # noqa: F401
2525

2626

2727
def wrap_method(
28-
func,
29-
default_retry=None,
30-
default_timeout=None,
31-
client_info=client_info.DEFAULT_CLIENT_INFO,
28+
func,
29+
default_retry=None,
30+
default_timeout=None,
31+
client_info=client_info.DEFAULT_CLIENT_INFO,
3232
):
3333
"""Wrap an async RPC method with common behavior.
3434
@@ -41,5 +41,6 @@ def wrap_method(
4141

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

44-
return general_helpers.wraps(func)(_GapicCallable(
45-
func, default_retry, default_timeout, metadata=metadata))
44+
return general_helpers.wraps(func)(
45+
_GapicCallable(func, default_retry, default_timeout, metadata=metadata)
46+
)

google/api_core/grpc_helpers.py

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,9 @@ def error_remapped_callable(*args, **kwargs):
157157
# hidden flag to see if pre-fetching is disabled.
158158
# https://github.com/googleapis/python-pubsub/issues/93#issuecomment-630762257
159159
prefetch_first = getattr(callable_, "_prefetch_first_result_", True)
160-
return _StreamingResponseIterator(result, prefetch_first_result=prefetch_first)
160+
return _StreamingResponseIterator(
161+
result, prefetch_first_result=prefetch_first
162+
)
161163
except grpc.RpcError as exc:
162164
six.raise_from(exceptions.from_grpc_error(exc), exc)
163165

@@ -187,13 +189,14 @@ def wrap_errors(callable_):
187189

188190

189191
def _create_composite_credentials(
190-
credentials=None,
191-
credentials_file=None,
192-
default_scopes=None,
193-
scopes=None,
194-
ssl_credentials=None,
195-
quota_project_id=None,
196-
default_host=None):
192+
credentials=None,
193+
credentials_file=None,
194+
default_scopes=None,
195+
scopes=None,
196+
ssl_credentials=None,
197+
quota_project_id=None,
198+
default_host=None,
199+
):
197200
"""Create the composite credentials for secure channels.
198201
199202
Args:
@@ -227,20 +230,20 @@ def _create_composite_credentials(
227230

228231
if credentials_file:
229232
credentials, _ = google.auth.load_credentials_from_file(
230-
credentials_file,
231-
scopes=scopes,
232-
default_scopes=default_scopes
233+
credentials_file, scopes=scopes, default_scopes=default_scopes
233234
)
234235
elif credentials:
235236
credentials = google.auth.credentials.with_scopes_if_required(
236-
credentials,
237-
scopes=scopes,
238-
default_scopes=default_scopes
237+
credentials, scopes=scopes, default_scopes=default_scopes
239238
)
240239
else:
241-
credentials, _ = google.auth.default(scopes=scopes, default_scopes=default_scopes)
240+
credentials, _ = google.auth.default(
241+
scopes=scopes, default_scopes=default_scopes
242+
)
242243

243-
if quota_project_id and isinstance(credentials, google.auth.credentials.CredentialsWithQuotaProject):
244+
if quota_project_id and isinstance(
245+
credentials, google.auth.credentials.CredentialsWithQuotaProject
246+
):
244247
credentials = credentials.with_quota_project(quota_project_id)
245248

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

259262
# Combine the ssl credentials and the authorization credentials.
260-
return grpc.composite_channel_credentials(
261-
ssl_credentials, google_auth_credentials
262-
)
263+
return grpc.composite_channel_credentials(ssl_credentials, google_auth_credentials)
263264

264265

265266
def create_channel(
266-
target,
267-
credentials=None,
268-
scopes=None,
269-
ssl_credentials=None,
270-
credentials_file=None,
271-
quota_project_id=None,
272-
default_scopes=None,
273-
default_host=None,
274-
**kwargs):
267+
target,
268+
credentials=None,
269+
scopes=None,
270+
ssl_credentials=None,
271+
credentials_file=None,
272+
quota_project_id=None,
273+
default_scopes=None,
274+
default_host=None,
275+
**kwargs
276+
):
275277
"""Create a secure channel with credentials.
276278
277279
Args:

google/api_core/grpc_helpers_async.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636

3737

3838
class _WrappedCall(aio.Call):
39-
4039
def __init__(self):
4140
self._call = None
4241

@@ -80,7 +79,6 @@ async def wait_for_connection(self):
8079

8180

8281
class _WrappedUnaryResponseMixin(_WrappedCall):
83-
8482
def __await__(self):
8583
try:
8684
response = yield from self._call.__await__()
@@ -90,7 +88,6 @@ def __await__(self):
9088

9189

9290
class _WrappedStreamResponseMixin(_WrappedCall):
93-
9491
def __init__(self):
9592
self._wrapped_async_generator = None
9693

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

118115

119116
class _WrappedStreamRequestMixin(_WrappedCall):
120-
121117
async def write(self, request):
122118
try:
123119
await self._call.write(request)
@@ -142,11 +138,15 @@ class _WrappedUnaryStreamCall(_WrappedStreamResponseMixin, aio.UnaryStreamCall):
142138
"""Wrapped UnaryStreamCall to map exceptions."""
143139

144140

145-
class _WrappedStreamUnaryCall(_WrappedUnaryResponseMixin, _WrappedStreamRequestMixin, aio.StreamUnaryCall):
141+
class _WrappedStreamUnaryCall(
142+
_WrappedUnaryResponseMixin, _WrappedStreamRequestMixin, aio.StreamUnaryCall
143+
):
146144
"""Wrapped StreamUnaryCall to map exceptions."""
147145

148146

149-
class _WrappedStreamStreamCall(_WrappedStreamRequestMixin, _WrappedStreamResponseMixin, aio.StreamStreamCall):
147+
class _WrappedStreamStreamCall(
148+
_WrappedStreamRequestMixin, _WrappedStreamResponseMixin, aio.StreamStreamCall
149+
):
150150
"""Wrapped StreamStreamCall to map exceptions."""
151151

152152

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

182182
await call.wait_for_connection()
183183
return call
@@ -207,15 +207,16 @@ def wrap_errors(callable_):
207207

208208

209209
def create_channel(
210-
target,
211-
credentials=None,
212-
scopes=None,
213-
ssl_credentials=None,
214-
credentials_file=None,
215-
quota_project_id=None,
216-
default_scopes=None,
217-
default_host=None,
218-
**kwargs):
210+
target,
211+
credentials=None,
212+
scopes=None,
213+
ssl_credentials=None,
214+
credentials_file=None,
215+
quota_project_id=None,
216+
default_scopes=None,
217+
default_host=None,
218+
**kwargs
219+
):
219220
"""Create an AsyncIO secure channel with credentials.
220221
221222
Args:
@@ -251,7 +252,7 @@ def create_channel(
251252
default_scopes=default_scopes,
252253
ssl_credentials=ssl_credentials,
253254
quota_project_id=quota_project_id,
254-
default_host=default_host
255+
default_host=default_host,
255256
)
256257

257258
return aio.secure_channel(target, composite_credentials, **kwargs)

google/api_core/iam.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -450,10 +450,7 @@ def to_api_repr(self):
450450
for binding in self._bindings:
451451
members = binding.get("members")
452452
if members:
453-
new_binding = {
454-
"role": binding["role"],
455-
"members": sorted(members)
456-
}
453+
new_binding = {"role": binding["role"], "members": sorted(members)}
457454
condition = binding.get("condition")
458455
if condition:
459456
new_binding["condition"] = condition

google/api_core/operation.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,12 @@ def from_grpc(operation, operations_stub, result_type, grpc_metadata=None, **kwa
310310
~.api_core.operation.Operation: The operation future to track the given
311311
operation.
312312
"""
313-
refresh = functools.partial(_refresh_grpc, operations_stub, operation.name, metadata=grpc_metadata)
314-
cancel = functools.partial(_cancel_grpc, operations_stub, operation.name, metadata=grpc_metadata)
313+
refresh = functools.partial(
314+
_refresh_grpc, operations_stub, operation.name, metadata=grpc_metadata
315+
)
316+
cancel = functools.partial(
317+
_cancel_grpc, operations_stub, operation.name, metadata=grpc_metadata
318+
)
315319
return Operation(operation, refresh, cancel, result_type, **kwargs)
316320

317321

@@ -338,6 +342,10 @@ def from_gapic(operation, operations_client, result_type, grpc_metadata=None, **
338342
~.api_core.operation.Operation: The operation future to track the given
339343
operation.
340344
"""
341-
refresh = functools.partial(operations_client.get_operation, operation.name, metadata=grpc_metadata)
342-
cancel = functools.partial(operations_client.cancel_operation, operation.name, metadata=grpc_metadata)
345+
refresh = functools.partial(
346+
operations_client.get_operation, operation.name, metadata=grpc_metadata
347+
)
348+
cancel = functools.partial(
349+
operations_client.cancel_operation, operation.name, metadata=grpc_metadata
350+
)
343351
return Operation(operation, refresh, cancel, result_type, **kwargs)

google/api_core/operation_async.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,10 @@ def from_gapic(operation, operations_client, result_type, grpc_metadata=None, **
212212
~.api_core.operation.Operation: The operation future to track the given
213213
operation.
214214
"""
215-
refresh = functools.partial(operations_client.get_operation, operation.name, metadata=grpc_metadata)
216-
cancel = functools.partial(operations_client.cancel_operation, operation.name, metadata=grpc_metadata)
215+
refresh = functools.partial(
216+
operations_client.get_operation, operation.name, metadata=grpc_metadata
217+
)
218+
cancel = functools.partial(
219+
operations_client.cancel_operation, operation.name, metadata=grpc_metadata
220+
)
217221
return AsyncOperation(operation, refresh, cancel, result_type, **kwargs)

google/api_core/operations_v1/operations_async_client.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ async def get_operation(
125125
metadata = metadata or []
126126
metadata.append(gapic_v1.routing_header.to_grpc_metadata({"name": name}))
127127

128-
return await self._get_operation(request, retry=retry, timeout=timeout, metadata=metadata)
128+
return await self._get_operation(
129+
request, retry=retry, timeout=timeout, metadata=metadata
130+
)
129131

130132
async def list_operations(
131133
self,
@@ -192,7 +194,9 @@ async def list_operations(
192194
metadata.append(gapic_v1.routing_header.to_grpc_metadata({"name": name}))
193195

194196
# Create the method used to fetch pages
195-
method = functools.partial(self._list_operations, retry=retry, timeout=timeout, metadata=metadata)
197+
method = functools.partial(
198+
self._list_operations, retry=retry, timeout=timeout, metadata=metadata
199+
)
196200

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

263-
await self._cancel_operation(request, retry=retry, timeout=timeout, metadata=metadata)
267+
await self._cancel_operation(
268+
request, retry=retry, timeout=timeout, metadata=metadata
269+
)
264270

265271
async def delete_operation(
266272
self,
@@ -311,4 +317,6 @@ async def delete_operation(
311317
metadata = metadata or []
312318
metadata.append(gapic_v1.routing_header.to_grpc_metadata({"name": name}))
313319

314-
await self._delete_operation(request, retry=retry, timeout=timeout, metadata=metadata)
320+
await self._delete_operation(
321+
request, retry=retry, timeout=timeout, metadata=metadata
322+
)

0 commit comments

Comments
 (0)