Skip to content

Commit 4a20fc6

Browse files
committed
lint changes
1 parent 019a0d8 commit 4a20fc6

File tree

12 files changed

+139
-91
lines changed

12 files changed

+139
-91
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: 2 additions & 3 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

@@ -213,9 +214,7 @@ def _use_client_cert(self):
213214
if hasattr(mtls, "should_use_client_cert"):
214215
use_client_cert = mtls.should_use_client_cert()
215216
else:
216-
use_client_cert = (
217-
os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE") == "true"
218-
)
217+
use_client_cert = os.getenv("GOOGLE_API_USE_CLIENT_CERTIFICATE") == "true"
219218
return use_client_cert
220219

221220
@abstractmethod

google/cloud/storage/client.py

Lines changed: 5 additions & 2 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,11 +140,13 @@ 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

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,43 +42,64 @@ 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
def test_ctor_mtls_raises_error(self):
5664
credentials = _make_credentials()
5765

5866
# Simulate environment where mTLS is enabled
59-
with mock.patch("google.cloud.storage.abstracts.base_client.BaseClient._use_client_cert", new_callable=mock.PropertyMock) as mock_mtls:
67+
with mock.patch(
68+
"google.cloud.storage.abstracts.base_client.BaseClient._use_client_cert",
69+
new_callable=mock.PropertyMock,
70+
) as mock_mtls:
6071
mock_mtls.return_value = True
6172

62-
with pytest.raises(ValueError, match="Async Client currently do not support mTLS"):
73+
with pytest.raises(
74+
ValueError, match="Async Client currently do not support mTLS"
75+
):
6376
self._make_one(credentials=credentials)
6477

6578
def test_ctor_w_async_http_passed(self):
6679
credentials = _make_credentials()
6780
async_http = mock.Mock()
6881

69-
with mock.patch("google.cloud.storage._experimental.asyncio.async_client.AsyncJSONConnection") as MockConn:
82+
with mock.patch(
83+
"google.cloud.storage._experimental.asyncio.async_client.AsyncJSONConnection"
84+
) as MockConn:
7085
client = self._make_one(
71-
project="PROJECT",
72-
credentials=credentials,
73-
_async_http=async_http
86+
project="PROJECT", credentials=credentials, _async_http=async_http
7487
)
7588

7689
client._json_connection
77-
MockConn.assert_called_once_with(client, _async_http=async_http, credentials=client.credentials, client_info=None, api_endpoint=None)
90+
MockConn.assert_called_once_with(
91+
client,
92+
_async_http=async_http,
93+
credentials=client.credentials,
94+
client_info=None,
95+
api_endpoint=None,
96+
)
7897

7998
def test_bucket_not_implemented(self):
8099
credentials = _make_credentials()
81-
with mock.patch("google.cloud.storage._experimental.asyncio.async_client.AsyncJSONConnection"):
100+
with mock.patch(
101+
"google.cloud.storage._experimental.asyncio.async_client.AsyncJSONConnection"
102+
):
82103
client = self._make_one(project="PROJECT", credentials=credentials)
83104

84105
with pytest.raises(NotImplementedError):

0 commit comments

Comments
 (0)