Skip to content
This repository was archived by the owner on Apr 1, 2026. It is now read-only.

Commit aec2577

Browse files
committed
fixed lint
1 parent 9fece96 commit aec2577

9 files changed

Lines changed: 72 additions & 43 deletions

File tree

google/cloud/bigtable/data/_async/client.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@
9898
BigtableAsyncClient as GapicClient,
9999
)
100100
from google.cloud.bigtable.data._async.mutations_batcher import _MB_SIZE
101-
from google.cloud.bigtable.data._async.metrics_interceptor import AsyncBigtableMetricsInterceptor as MetricInterceptorType
101+
from google.cloud.bigtable.data._async.metrics_interceptor import (
102+
AsyncBigtableMetricsInterceptor as MetricInterceptorType,
103+
)
102104
from google.cloud.bigtable.data._async._swappable_channel import (
103105
AsyncSwappableChannel,
104106
)
@@ -109,7 +111,9 @@
109111
from google.cloud.bigtable_v2.services.bigtable.transports import BigtableGrpcTransport as TransportType # type: ignore
110112
from google.cloud.bigtable_v2.services.bigtable import BigtableClient as GapicClient # type: ignore
111113
from google.cloud.bigtable.data._sync_autogen.mutations_batcher import _MB_SIZE
112-
from google.cloud.bigtable.data._sync_autogen.metrics_interceptor import BigtableMetricsInterceptor as MetricInterceptorType
114+
from google.cloud.bigtable.data._sync_autogen.metrics_interceptor import (
115+
BigtableMetricsInterceptor as MetricInterceptorType,
116+
)
113117
from google.cloud.bigtable.data._sync_autogen._swappable_channel import ( # noqa: F401
114118
SwappableChannel,
115119
)
@@ -272,9 +276,12 @@ def _build_grpc_channel(self, *args, **kwargs) -> AsyncSwappableChannel:
272276
create_channel_fn = partial(TransportType.create_channel, *args, **kwargs)
273277
else:
274278
# attach sync interceptors in create_channel_fn
275-
create_channel_fn = lambda: intercept_channel(
276-
TransportType.create_channel(*args, **kwargs), self._metrics_interceptor
277-
)
279+
def create_channel_fn():
280+
return intercept_channel(
281+
TransportType.create_channel(*args, **kwargs),
282+
self._metrics_interceptor,
283+
)
284+
278285
new_channel = AsyncSwappableChannel(create_channel_fn)
279286
if CrossSync.is_async:
280287
# attach async interceptors

google/cloud/bigtable/data/_async/metrics_interceptor.py

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
# limitations under the License
1414
from __future__ import annotations
1515

16-
import time
17-
from typing import Any, Callable
1816
from functools import wraps
19-
from google.cloud.bigtable.data._metrics.data_model import OPERATION_INTERCEPTOR_METADATA_KEY
17+
from google.cloud.bigtable.data._metrics.data_model import (
18+
OPERATION_INTERCEPTOR_METADATA_KEY,
19+
)
2020
from google.cloud.bigtable.data._metrics.data_model import ActiveOperationMetric
2121
from google.cloud.bigtable.data._metrics.data_model import OperationState
2222

@@ -38,9 +38,17 @@ def _with_operation_from_metadata(func):
3838
Decorator for interceptor methods to extract the active operation
3939
from metadata and pass it to the decorated function.
4040
"""
41+
4142
@wraps(func)
4243
def wrapper(self, continuation, client_call_details, request):
43-
key = next((m[1] for m in client_call_details.metadata if m[0] == OPERATION_INTERCEPTOR_METADATA_KEY), None)
44+
key = next(
45+
(
46+
m[1]
47+
for m in client_call_details.metadata
48+
if m[0] == OPERATION_INTERCEPTOR_METADATA_KEY
49+
),
50+
None,
51+
)
4452
operation: "ActiveOperationMetric" = self.operation_map.get(key)
4553
if operation:
4654
# start a new attempt if not started
@@ -51,13 +59,14 @@ def wrapper(self, continuation, client_call_details, request):
5159
else:
5260
# if operation not found, return unwrapped continuation
5361
return continuation(client_call_details, request)
62+
5463
return wrapper
5564

5665

57-
@CrossSync.convert_class(
58-
sync_name="BigtableMetricsInterceptor"
59-
)
60-
class AsyncBigtableMetricsInterceptor(UnaryUnaryClientInterceptor, UnaryStreamClientInterceptor):
66+
@CrossSync.convert_class(sync_name="BigtableMetricsInterceptor")
67+
class AsyncBigtableMetricsInterceptor(
68+
UnaryUnaryClientInterceptor, UnaryStreamClientInterceptor
69+
):
6170
"""
6271
An async gRPC interceptor to add client metadata and print server metadata.
6372
"""
@@ -89,7 +98,9 @@ def on_attempt_complete(self, attempt, operation):
8998

9099
@CrossSync.convert
91100
@_with_operation_from_metadata
92-
async def intercept_unary_unary(self, operation, continuation, client_call_details, request):
101+
async def intercept_unary_unary(
102+
self, operation, continuation, client_call_details, request
103+
):
93104
encountered_exc: Exception | None = None
94105
call = None
95106
try:
@@ -101,8 +112,7 @@ async def intercept_unary_unary(self, operation, continuation, client_call_detai
101112
finally:
102113
if call is not None:
103114
metadata = (
104-
await call.trailing_metadata()
105-
+ await call.initial_metadata()
115+
await call.trailing_metadata() + await call.initial_metadata()
106116
)
107117
operation.add_response_metadata(metadata)
108118
if encountered_exc is not None:
@@ -111,7 +121,9 @@ async def intercept_unary_unary(self, operation, continuation, client_call_detai
111121

112122
@CrossSync.convert
113123
@_with_operation_from_metadata
114-
async def intercept_unary_stream(self, operation, continuation, client_call_details, request):
124+
async def intercept_unary_stream(
125+
self, operation, continuation, client_call_details, request
126+
):
115127
async def response_wrapper(call):
116128
encountered_exc = None
117129
try:
@@ -123,12 +135,11 @@ async def response_wrapper(call):
123135
raise
124136
finally:
125137
metadata = (
126-
await call.trailing_metadata()
127-
+ await call.initial_metadata()
138+
await call.trailing_metadata() + await call.initial_metadata()
128139
)
129140
operation.add_response_metadata(metadata)
130141
if encountered_exc is not None:
131142
# end attempt. If it succeeded, let higher levels decide when to end operation
132143
operation.end_attempt_with_status(encountered_exc)
133144

134-
return response_wrapper(await continuation(client_call_details, request))
145+
return response_wrapper(await continuation(client_call_details, request))

google/cloud/bigtable/data/_helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,4 +277,4 @@ def get_attempt_backoff(self, attempt_idx) -> float:
277277
"""
278278
returns the backoff time for a specific attempt index, starting at 0.
279279
"""
280-
return self.history[attempt_idx]
280+
return self.history[attempt_idx]

google/cloud/bigtable/data/_metrics/data_model.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414
from __future__ import annotations
1515

16-
from typing import Callable, Any, Tuple, cast, TYPE_CHECKING
16+
from typing import Callable, Tuple, cast, TYPE_CHECKING
1717

1818
import time
1919
import re
@@ -48,7 +48,7 @@
4848

4949
INVALID_STATE_ERROR = "Invalid state for {}: {}"
5050

51-
OPERATION_INTERCEPTOR_METADATA_KEY = 'x-goog-operation-key'
51+
OPERATION_INTERCEPTOR_METADATA_KEY = "x-goog-operation-key"
5252

5353

5454
class OperationType(Enum):
@@ -443,4 +443,4 @@ async def __aexit__(self, exc_type, exc_val, exc_tb):
443443
if exc_val is None:
444444
self.end_with_success()
445445
else:
446-
self.end_with_status(exc_val)
446+
self.end_with_status(exc_val)

google/cloud/bigtable/data/_metrics/metrics_controller.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,13 @@
2020
from google.cloud.bigtable.data._metrics.data_model import OperationType
2121

2222
if TYPE_CHECKING:
23-
from google.cloud.bigtable.data._async.metrics_interceptor import AsyncBigtableMetricsInterceptor
24-
from google.cloud.bigtable.data._sync_autogen.metrics_interceptor import BigtableMetricsInterceptor
23+
from google.cloud.bigtable.data._async.metrics_interceptor import (
24+
AsyncBigtableMetricsInterceptor,
25+
)
26+
from google.cloud.bigtable.data._sync_autogen.metrics_interceptor import (
27+
BigtableMetricsInterceptor,
28+
)
29+
2530

2631
class BigtableClientSideMetricsController:
2732
"""
@@ -31,10 +36,11 @@ class BigtableClientSideMetricsController:
3136
registered with the handlers associated with this controller.
3237
"""
3338

34-
def __init__(self,
35-
interceptor: AsyncBigtableMetricsInterceptor | BigtableMetricsInterceptor,
39+
def __init__(
40+
self,
41+
interceptor: AsyncBigtableMetricsInterceptor | BigtableMetricsInterceptor,
3642
handlers: list[MetricsHandler] | None = None,
37-
**kwargs
43+
**kwargs,
3844
):
3945
"""
4046
Initializes the metrics controller.
@@ -69,4 +75,4 @@ def create_operation(
6975
handlers = self.handlers + kwargs.pop("handlers", [])
7076
new_op = ActiveOperationMetric(op_type, **kwargs, handlers=handlers)
7177
self.interceptor.register_operation(new_op)
72-
return new_op
78+
return new_op

google/cloud/bigtable/data/_sync_autogen/client.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,13 @@ def _build_grpc_channel(self, *args, **kwargs) -> SwappableChannel:
201201
if self._emulator_host is not None:
202202
create_channel_fn = partial(insecure_channel, self._emulator_host)
203203
else:
204-
create_channel_fn = lambda: intercept_channel(
205-
TransportType.create_channel(*args, **kwargs), self._metrics_interceptor
206-
)
204+
205+
def create_channel_fn():
206+
return intercept_channel(
207+
TransportType.create_channel(*args, **kwargs),
208+
self._metrics_interceptor,
209+
)
210+
207211
new_channel = SwappableChannel(create_channel_fn)
208212
return new_channel
209213

tests/system/data/test_system_async.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -302,15 +302,11 @@ async def test_channel_refresh(self, table_id, instance_id, temp_rows):
302302
assert channel_wrapper._channel is not first_channel
303303
# ensure interceptors are kept (gapic's logging interceptor, and metric interceptor)
304304
if CrossSync.is_async:
305-
unary_interceptors = (
306-
updated_channel._unary_unary_interceptors
307-
)
305+
unary_interceptors = updated_channel._unary_unary_interceptors
308306
assert len(unary_interceptors) == 2
309307
assert GapicInterceptor in [type(i) for i in unary_interceptors]
310308
assert client._metrics_interceptor in unary_interceptors
311-
stream_interceptors = (
312-
updated_channel._unary_stream_interceptors
313-
)
309+
stream_interceptors = updated_channel._unary_stream_interceptors
314310
assert len(stream_interceptors) == 1
315311
assert client._metrics_interceptor in stream_interceptors
316312
else:

tests/unit/data/_async/test_client.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@
5454
from google.cloud.bigtable.data._async._swappable_channel import (
5555
AsyncSwappableChannel,
5656
)
57-
from google.cloud.bigtable.data._async.metrics_interceptor import AsyncBigtableMetricsInterceptor
57+
from google.cloud.bigtable.data._async.metrics_interceptor import (
58+
AsyncBigtableMetricsInterceptor,
59+
)
5860

5961
CrossSync.add_mapping("grpc_helpers", grpc_helpers_async)
6062
CrossSync.add_mapping("SwappableChannel", AsyncSwappableChannel)
@@ -65,7 +67,9 @@
6567
from google.cloud.bigtable.data._sync_autogen._swappable_channel import (
6668
SwappableChannel,
6769
)
68-
from google.cloud.bigtable.data._sync_autogen.metrics_interceptor import BigtableMetricsInterceptor
70+
from google.cloud.bigtable.data._sync_autogen.metrics_interceptor import (
71+
BigtableMetricsInterceptor,
72+
)
6973

7074
CrossSync.add_mapping("grpc_helpers", grpc_helpers)
7175
CrossSync.add_mapping("SwappableChannel", SwappableChannel)

tests/unit/data/test__helpers.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,12 +269,13 @@ def test_get_retryable_errors(self, input_codes, input_table, expected):
269269

270270

271271
class TestTrackedBackoffGenerator:
272-
273272
def test_tracked_backoff_generator_history(self):
274273
"""
275274
Should be able to retrieve historical results from backoff generator
276275
"""
277-
generator = _helpers.TrackedBackoffGenerator(initial=0, multiplier=2, maximum=10)
276+
generator = _helpers.TrackedBackoffGenerator(
277+
initial=0, multiplier=2, maximum=10
278+
)
278279
got_list = [next(generator) for _ in range(20)]
279280

280281
# check all values are correct

0 commit comments

Comments
 (0)