Skip to content

Commit 5c6297f

Browse files
committed
lint changes
1 parent 0e9a775 commit 5c6297f

File tree

13 files changed

+185
-123
lines changed

13 files changed

+185
-123
lines changed

google/cloud/storage/_experimental/asyncio/abstracts/async_connection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def __init__(self, client, client_info=None):
4545
)
4646
self._client_info.client_library_version = __version__
4747
self._extra_headers = {}
48-
48+
4949
@property
5050
def extra_headers(self):
5151
"""Returns extra headers to send with every request."""
@@ -71,4 +71,4 @@ def user_agent(self, value):
7171
self._client_info.user_agent = value
7272

7373
async def close(self):
74-
pass
74+
pass

google/cloud/storage/_experimental/asyncio/async_client.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616

1717
from google.cloud.storage._experimental.asyncio.async_creds import AsyncCredsWrapper
1818
from google.cloud.storage.abstracts.base_client import BaseClient
19-
from google.cloud.storage._experimental.asyncio.utility.async_json_connection import AsyncJSONConnection
19+
from google.cloud.storage._experimental.asyncio.utility.async_json_connection import (
20+
AsyncJSONConnection,
21+
)
2022
from google.cloud.storage.abstracts import base_client
2123

2224
_marker = base_client.marker
@@ -49,9 +51,11 @@ def __init__(
4951
client_info=client_info,
5052
client_options=client_options,
5153
extra_headers=extra_headers,
52-
api_key=api_key
54+
api_key=api_key,
5355
)
54-
self.credentials = AsyncCredsWrapper(self._credentials) # self._credential is synchronous.
56+
self.credentials = AsyncCredsWrapper(
57+
self._credentials
58+
) # self._credential is synchronous.
5559
self._async_http = _async_http
5660

5761
# We need both, as the same client can be used for multiple buckets.
@@ -65,13 +69,18 @@ def _grpc_connection(self):
6569
@property
6670
def _json_connection(self):
6771
if not self._json_connection_internal:
68-
self._json_connection_internal = AsyncJSONConnection(self, _async_http=self._async_http, credentials=self.credentials, **self.connection_kw_args)
72+
self._json_connection_internal = AsyncJSONConnection(
73+
self,
74+
_async_http=self._async_http,
75+
credentials=self.credentials,
76+
**self.connection_kw_args,
77+
)
6978
return self._json_connection_internal
7079

7180
async def close(self):
7281
if self._json_connection_internal:
7382
await self._json_connection_internal.close()
74-
83+
7584
if self._grpc_connection_internal:
7685
await self._grpc_connection_internal.close()
7786

google/cloud/storage/_experimental/asyncio/async_creds.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,23 @@
55

66
try:
77
from google.auth.aio import credentials as aio_creds_module
8+
89
BaseCredentials = aio_creds_module.Credentials
910
_AIO_AVAILABLE = True
1011
except ImportError:
1112
BaseCredentials = object
1213
_AIO_AVAILABLE = False
1314

15+
1416
class AsyncCredsWrapper(BaseCredentials):
1517
"""Wraps synchronous Google Auth credentials to provide an asynchronous interface.
1618
1719
Args:
18-
sync_creds (google.auth.credentials.Credentials): The synchronous credentials
20+
sync_creds (google.auth.credentials.Credentials): The synchronous credentials
1921
instance to wrap.
2022
2123
Raises:
22-
ImportError: If instantiated in an environment where 'google.auth.aio'
24+
ImportError: If instantiated in an environment where 'google.auth.aio'
2325
is not available.
2426
"""
2527

@@ -36,9 +38,7 @@ def __init__(self, sync_creds):
3638
async def refresh(self, request):
3739
"""Refreshes the access token."""
3840
loop = asyncio.get_running_loop()
39-
await loop.run_in_executor(
40-
None, self.creds.refresh, Request()
41-
)
41+
await loop.run_in_executor(None, self.creds.refresh, Request())
4242

4343
@property
4444
def valid(self):

google/cloud/storage/_experimental/asyncio/async_helpers.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ async def _do_nothing_page_start(iterator, page, response):
2424
# pylint: disable=unused-argument
2525
pass
2626

27+
2728
class AsyncHTTPIterator(AsyncIterator):
2829
"""A generic class for iterating through HTTP/JSON API list responses asynchronously.
2930
@@ -32,15 +33,15 @@ class AsyncHTTPIterator(AsyncIterator):
3233
api_request (Callable): The **async** function to use to make API requests.
3334
This must be an awaitable.
3435
path (str): The method path to query for the list of items.
35-
item_to_value (Callable[AsyncIterator, Any]): Callable to convert an item
36+
item_to_value (Callable[AsyncIterator, Any]): Callable to convert an item
3637
from the type in the JSON response into a native object.
3738
items_key (str): The key in the API response where the list of items
3839
can be found.
3940
page_token (str): A token identifying a page in a result set.
4041
page_size (int): The maximum number of results to fetch per page.
4142
max_results (int): The maximum number of results to fetch.
4243
extra_params (dict): Extra query string parameters for the API call.
43-
page_start (Callable): Callable to provide special behavior after a new page
44+
page_start (Callable): Callable to provide special behavior after a new page
4445
is created.
4546
next_token (str): The name of the field used in the response for page tokens.
4647
"""
@@ -137,6 +138,4 @@ def _get_query_params(self):
137138
async def _get_next_page_response(self):
138139
"""Requests the next page from the path provided asynchronously."""
139140
params = self._get_query_params()
140-
return await self.api_request(
141-
method="GET", path=self.path, query_params=params
142-
)
141+
return await self.api_request(method="GET", path=self.path, query_params=params)

google/cloud/storage/_experimental/asyncio/utility/async_json_connection.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,19 @@
2424
from google.cloud.storage import _http as storage_http
2525
from google.cloud.storage import _helpers
2626
from google.cloud.storage._opentelemetry_tracing import create_trace_span
27-
from google.cloud.storage._experimental.asyncio.abstracts.async_connection import AsyncConnection
27+
from google.cloud.storage._experimental.asyncio.abstracts.async_connection import (
28+
AsyncConnection,
29+
)
2830

2931
try:
3032
from google.auth.aio.transport import sessions
33+
3134
AsyncSession = sessions.AsyncAuthorizedSession
3235
_AIO_AVAILABLE = True
3336
except ImportError:
3437
_AIO_AVAILABLE = False
3538

39+
3640
class AsyncJSONConnection(AsyncConnection):
3741
"""Implementation of Async JSON connection
3842
@@ -42,7 +46,14 @@ class AsyncJSONConnection(AsyncConnection):
4246
api_endpoint: The API endpoint to use.
4347
"""
4448

45-
def __init__(self, client, client_info=None, api_endpoint=None, _async_http=None, credentials=None):
49+
def __init__(
50+
self,
51+
client,
52+
client_info=None,
53+
api_endpoint=None,
54+
_async_http=None,
55+
credentials=None,
56+
):
4657
if not _AIO_AVAILABLE:
4758
# Python 3.9 or less comes with an older version of google-auth library which doesn't support asyncio
4859
raise ImportError(
@@ -55,10 +66,10 @@ def __init__(self, client, client_info=None, api_endpoint=None, _async_http=None
5566
self.API_BASE_URL = api_endpoint or storage_http.Connection.DEFAULT_API_ENDPOINT
5667
self.API_VERSION = storage_http.Connection.API_VERSION
5768
self.API_URL_TEMPLATE = storage_http.Connection.API_URL_TEMPLATE
58-
69+
5970
self.credentials = credentials
6071
self._async_http_internal = _async_http
61-
self._async_http_passed_by_user = (_async_http is not None)
72+
self._async_http_passed_by_user = _async_http is not None
6273

6374
@property
6475
def async_http(self):
@@ -69,7 +80,10 @@ def async_http(self):
6980

7081
async def close(self):
7182
"""Close the session, if it exists"""
72-
if self._async_http_internal is not None and not self._async_http_passed_by_user:
83+
if (
84+
self._async_http_internal is not None
85+
and not self._async_http_passed_by_user
86+
):
7387
await self._async_http_internal.close()
7488

7589
async def _make_request(

google/cloud/storage/_media/requests/download.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,5 @@ def flush(self):
774774
def has_unconsumed_tail(self) -> bool:
775775
return self._decoder.has_unconsumed_tail
776776

777-
778777
else: # pragma: NO COVER
779778
_BrotliDecoder = None # type: ignore # pragma: NO COVER

google/cloud/storage/abstracts/base_client.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
marker = object()
3232

33+
3334
class BaseClient(ClientWithProject, ABC):
3435
"""Abstract class for python-storage Client"""
3536

@@ -248,7 +249,7 @@ def _connection(self, value):
248249
"""
249250
if self._base_connection is not None:
250251
raise ValueError("Connection already set on client")
251-
self._base_connection = value
252+
self._base_connection = value
252253

253254
@property
254255
def _use_client_cert(self):
@@ -260,9 +261,7 @@ def _use_client_cert(self):
260261
if hasattr(mtls, "should_use_client_cert"):
261262
use_client_cert = mtls.should_use_client_cert()
262263
else:
263-
use_client_cert = (
264-
os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE") == "true"
265-
)
264+
use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE") == "true"
266265
return use_client_cert
267266

268267
def _push_batch(self, batch):

google/cloud/storage/client.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050

5151
_marker = base_client.marker
5252

53+
5354
def _buckets_page_start(iterator, page, response):
5455
"""Grab unreachable buckets after a :class:`~google.cloud.iterator.Page` started."""
5556
unreachable = response.get("unreachable", [])
@@ -139,15 +140,16 @@ def __init__(
139140
client_options=client_options,
140141
use_auth_w_custom_endpoint=use_auth_w_custom_endpoint,
141142
extra_headers=extra_headers,
142-
api_key=api_key
143+
api_key=api_key,
143144
)
144145

145146
# Pass extra_headers to Connection
146-
connection = Connection(self, **self.connection_kw_args) # connection_kw_args would always be set in base class
147+
connection = Connection(
148+
self, **self.connection_kw_args
149+
) # connection_kw_args would always be set in base class
147150
connection.extra_headers = extra_headers
148151
self._connection = connection
149152

150-
151153
def get_service_account_email(
152154
self, project=None, timeout=_DEFAULT_TIMEOUT, retry=DEFAULT_RETRY
153155
):

tests/unit/asyncio/test_async_client.py

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def _make_credentials():
2727

2828
@pytest.mark.skipif(
2929
sys.version_info < (3, 10),
30-
reason="Async Client requires Python 3.10+ due to google-auth-library asyncio support"
30+
reason="Async Client requires Python 3.10+ due to google-auth-library asyncio support",
3131
)
3232
class TestAsyncClient:
3333
@staticmethod
@@ -42,15 +42,23 @@ def test_ctor_defaults(self):
4242
credentials = _make_credentials()
4343

4444
# We mock AsyncJSONConnection to prevent network logic during init
45-
with mock.patch("google.cloud.storage._experimental.asyncio.async_client.AsyncJSONConnection") as MockConn:
45+
with mock.patch(
46+
"google.cloud.storage._experimental.asyncio.async_client.AsyncJSONConnection"
47+
) as MockConn:
4648
client = self._make_one(project=PROJECT, credentials=credentials)
4749

4850
assert client.project == PROJECT
4951

5052
# It is the instance of the Mock
5153
assert isinstance(client._json_connection, mock.Mock)
5254
assert client._json_connection == MockConn.return_value
53-
MockConn.assert_called_once_with(client, _async_http=None, credentials=client.credentials, client_info=None, api_endpoint=None)
55+
MockConn.assert_called_once_with(
56+
client,
57+
_async_http=None,
58+
credentials=client.credentials,
59+
client_info=None,
60+
api_endpoint=None,
61+
)
5462

5563
# Verify inheritance from BaseClient worked (batch stack, etc)
5664
assert client.current_batch is None
@@ -60,29 +68,42 @@ def test_ctor_mtls_raises_error(self):
6068
credentials = _make_credentials()
6169

6270
# Simulate environment where mTLS is enabled
63-
with mock.patch("google.cloud.storage.abstracts.base_client.BaseClient._use_client_cert", new_callable=mock.PropertyMock) as mock_mtls:
71+
with mock.patch(
72+
"google.cloud.storage.abstracts.base_client.BaseClient._use_client_cert",
73+
new_callable=mock.PropertyMock,
74+
) as mock_mtls:
6475
mock_mtls.return_value = True
6576

66-
with pytest.raises(ValueError, match="Async Client currently do not support mTLS"):
77+
with pytest.raises(
78+
ValueError, match="Async Client currently do not support mTLS"
79+
):
6780
self._make_one(credentials=credentials)
6881

6982
def test_ctor_w_async_http_passed(self):
7083
credentials = _make_credentials()
7184
async_http = mock.Mock()
7285

73-
with mock.patch("google.cloud.storage._experimental.asyncio.async_client.AsyncJSONConnection") as MockConn:
86+
with mock.patch(
87+
"google.cloud.storage._experimental.asyncio.async_client.AsyncJSONConnection"
88+
) as MockConn:
7489
client = self._make_one(
75-
project="PROJECT",
76-
credentials=credentials,
77-
_async_http=async_http
90+
project="PROJECT", credentials=credentials, _async_http=async_http
7891
)
7992

8093
client._json_connection
81-
MockConn.assert_called_once_with(client, _async_http=async_http, credentials=client.credentials, client_info=None, api_endpoint=None)
94+
MockConn.assert_called_once_with(
95+
client,
96+
_async_http=async_http,
97+
credentials=client.credentials,
98+
client_info=None,
99+
api_endpoint=None,
100+
)
82101

83102
def test_bucket_not_implemented(self):
84103
credentials = _make_credentials()
85-
with mock.patch("google.cloud.storage._experimental.asyncio.async_client.AsyncJSONConnection"):
104+
with mock.patch(
105+
"google.cloud.storage._experimental.asyncio.async_client.AsyncJSONConnection"
106+
):
86107
client = self._make_one(project="PROJECT", credentials=credentials)
87108

88109
with pytest.raises(NotImplementedError):

0 commit comments

Comments
 (0)