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

Commit 26cd601

Browse files
committed
fixed lint
1 parent 7d90a04 commit 26cd601

3 files changed

Lines changed: 46 additions & 35 deletions

File tree

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

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
__CROSS_SYNC_OUTPUT__ = "google.cloud.bigtable.data._sync_autogen._replaceable_channel"
2929

30+
3031
@CrossSync.convert_class(sync_name="_WrappedChannel", rm_aio=True)
3132
class _AsyncWrappedChannel(Channel):
3233
"""
@@ -49,15 +50,12 @@ def stream_unary(self, *args, **kwargs):
4950
def stream_stream(self, *args, **kwargs):
5051
return self._channel.stream_stream(*args, **kwargs)
5152

52-
# grace not supported by sync version
53-
@CrossSync.drop
54-
async def close(self, grace=None):
55-
return await self._channel.close(grace=grace)
56-
5753
async def channel_ready(self):
5854
return await self._channel.channel_ready()
5955

60-
@CrossSync.convert(sync_name="__enter__", replace_symbols={"__aenter__": "__enter__"})
56+
@CrossSync.convert(
57+
sync_name="__enter__", replace_symbols={"__aenter__": "__enter__"}
58+
)
6159
async def __aenter__(self):
6260
await self._channel.__aenter__()
6361
return self
@@ -75,7 +73,13 @@ async def wait_for_state_change(self, last_observed_state):
7573
def __getattr__(self, name):
7674
return getattr(self._channel, name)
7775

78-
if not CrossSync.is_async:
76+
if CrossSync.is_async:
77+
# grace not supported by sync version
78+
async def close(self, grace=None):
79+
return await self._channel.close(grace=grace)
80+
81+
else:
82+
# add required sync methods
7983

8084
def close(self):
8185
return self._channel.close()
@@ -87,9 +91,11 @@ def unsubscribe(self, callback):
8791
return self._channel.unsubscribe(callback)
8892

8993

90-
@CrossSync.convert_class(sync_name="_ReplaceableChannel", replace_symbols={"_AsyncWrappedChannel": "_WrappedChannel"})
94+
@CrossSync.convert_class(
95+
sync_name="_ReplaceableChannel",
96+
replace_symbols={"_AsyncWrappedChannel": "_WrappedChannel"},
97+
)
9198
class _AsyncReplaceableChannel(_AsyncWrappedChannel):
92-
9399
def __init__(self, channel_fn: Callable[[], Channel]):
94100
self._channel_fn = channel_fn
95101
self._channel = channel_fn()
@@ -100,13 +106,21 @@ def create_channel(self) -> Channel:
100106
# copy over interceptors
101107
# this is needed because of how gapic attaches the LoggingClientAIOInterceptor
102108
# sync channels add interceptors by wrapping, so this step isn't needed
103-
new_channel._unary_unary_interceptors = self._channel._unary_unary_interceptors
104-
new_channel._unary_stream_interceptors = self._channel._unary_stream_interceptors
105-
new_channel._stream_unary_interceptors = self._channel._stream_unary_interceptors
106-
new_channel._stream_stream_interceptors = self._channel._stream_stream_interceptors
109+
new_channel._unary_unary_interceptors = (
110+
self._channel._unary_unary_interceptors
111+
)
112+
new_channel._unary_stream_interceptors = (
113+
self._channel._unary_stream_interceptors
114+
)
115+
new_channel._stream_unary_interceptors = (
116+
self._channel._stream_unary_interceptors
117+
)
118+
new_channel._stream_stream_interceptors = (
119+
self._channel._stream_stream_interceptors
120+
)
107121
return new_channel
108122

109123
def replace_wrapped_channel(self, new_channel: Channel) -> Channel:
110124
old_channel = self._channel
111125
self._channel = new_channel
112-
return old_channel
126+
return old_channel

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,18 +92,18 @@
9292
from google.cloud.bigtable_v2.services.bigtable.transports import (
9393
BigtableGrpcAsyncIOTransport as TransportType,
9494
)
95-
from google.cloud.bigtable_v2.services.bigtable.transports.grpc_asyncio import (
96-
_LoggingClientAIOInterceptor
97-
)
9895
from google.cloud.bigtable.data._async.mutations_batcher import _MB_SIZE
99-
from google.cloud.bigtable.data._async._replaceable_channel import _AsyncReplaceableChannel
96+
from google.cloud.bigtable.data._async._replaceable_channel import (
97+
_AsyncReplaceableChannel,
98+
)
10099
else:
101100
from typing import Iterable # noqa: F401
102101
from grpc import insecure_channel
103-
from grpc import intercept_channel
104102
from google.cloud.bigtable_v2.services.bigtable.transports import BigtableGrpcTransport as TransportType # type: ignore
105103
from google.cloud.bigtable.data._sync_autogen.mutations_batcher import _MB_SIZE
106-
from google.cloud.bigtable.data._sync_autogen._replaceable_channel import _ReplaceableChannel
104+
from google.cloud.bigtable.data._sync_autogen._replaceable_channel import ( # noqa: F401
105+
_ReplaceableChannel,
106+
)
107107

108108

109109
if TYPE_CHECKING:
@@ -239,7 +239,9 @@ def __init__(
239239
stacklevel=2,
240240
)
241241

242-
@CrossSync.convert(replace_symbols={"_AsyncReplaceableChannel": "_ReplaceableChannel"})
242+
@CrossSync.convert(
243+
replace_symbols={"_AsyncReplaceableChannel": "_ReplaceableChannel"}
244+
)
243245
def _build_grpc_channel(self, *args, **kwargs) -> _AsyncReplaceableChannel:
244246
if self._emulator_host is not None:
245247
# emulators use insecure channel
@@ -248,7 +250,6 @@ def _build_grpc_channel(self, *args, **kwargs) -> _AsyncReplaceableChannel:
248250
create_channel_fn = partial(TransportType.create_channel, *args, **kwargs)
249251
return _AsyncReplaceableChannel(create_channel_fn)
250252

251-
252253
@staticmethod
253254
def _client_version() -> str:
254255
"""
@@ -351,7 +352,9 @@ def _invalidate_channel_stubs(self):
351352
self.transport._stubs = {}
352353
self.transport._prep_wrapped_messages(self.client_info)
353354

354-
@CrossSync.convert(replace_symbols={"_AsyncReplaceableChannel": "_ReplaceableChannel"})
355+
@CrossSync.convert(
356+
replace_symbols={"_AsyncReplaceableChannel": "_ReplaceableChannel"}
357+
)
355358
async def _manage_channel(
356359
self,
357360
refresh_interval_min: float = 60 * 35,

tests/unit/data/_async/test_client.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,18 @@
5151
if CrossSync.is_async:
5252
from google.api_core import grpc_helpers_async
5353
from google.cloud.bigtable.data._async.client import TableAsync
54-
from google.cloud.bigtable.data._async._replaceable_channel import _AsyncReplaceableChannel
54+
from google.cloud.bigtable.data._async._replaceable_channel import (
55+
_AsyncReplaceableChannel,
56+
)
5557

5658
CrossSync.add_mapping("grpc_helpers", grpc_helpers_async)
5759
CrossSync.add_mapping("ReplaceableChannel", _AsyncReplaceableChannel)
5860
else:
5961
from google.api_core import grpc_helpers
6062
from google.cloud.bigtable.data._sync_autogen.client import Table # noqa: F401
61-
from google.cloud.bigtable.data._sync_autogen._replaceable_channel import _ReplaceableChannel
63+
from google.cloud.bigtable.data._sync_autogen._replaceable_channel import (
64+
_ReplaceableChannel,
65+
)
6266

6367
CrossSync.add_mapping("grpc_helpers", grpc_helpers)
6468
CrossSync.add_mapping("ReplaceableChannel", _ReplaceableChannel)
@@ -388,18 +392,8 @@ async def test__manage_channel_ping_and_warm(self):
388392
"""
389393
_manage channel should call ping and warm internally
390394
"""
391-
import time
392395
import threading
393396

394-
if CrossSync.is_async:
395-
from google.cloud.bigtable_v2.services.bigtable.transports.grpc_asyncio import (
396-
_LoggingClientAIOInterceptor as Interceptor,
397-
)
398-
else:
399-
from google.cloud.bigtable_v2.services.bigtable.transports.grpc import (
400-
_LoggingClientInterceptor as Interceptor,
401-
)
402-
403397
client = self._make_client(project="project-id", use_emulator=True)
404398
orig_channel = client.transport.grpc_channel
405399
# should ping an warm all new channels, and old channels if sleeping

0 commit comments

Comments
 (0)