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

Commit 911a299

Browse files
committed
fixed lint
1 parent dd7453b commit 911a299

7 files changed

Lines changed: 18 additions & 27 deletions

File tree

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,8 @@ def __init__(
106106
self.is_retryable,
107107
metric.backoff_generator,
108108
operation_timeout,
109-
exception_factory=self._operation_metric.track_terminal_error(
110-
_retry_exception_factory
111-
),
112-
on_error=self._operation_metric.track_retryable_error,
109+
exception_factory=metric.track_terminal_error(_retry_exception_factory),
110+
on_error=metric.track_retryable_error,
113111
)
114112
# initialize state
115113
self.timeout_generator = _attempt_timeout_generator(

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,6 @@ async def merge_rows(
350350
except Exception as generic_exception:
351351
# handle exceptions in retry wrapper
352352
raise generic_exception
353-
else:
354-
self._operation_metric.end_with_success()
355353

356354
@staticmethod
357355
def _revise_request_rowset(

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def wrapper(self, continuation, client_call_details, request):
6767
async def _get_metadata(source) -> dict[str, str | bytes] | None:
6868
"""Helper to extract metadata from a call or RpcError"""
6969
try:
70+
metadata: Sequence[tuple[str, str | bytes]]
7071
if CrossSync.is_async:
7172
# grpc.aio returns metadata in Metadata objects
7273
if isinstance(source, AioRpcError):
@@ -79,11 +80,9 @@ async def _get_metadata(source) -> dict[str, str | bytes] | None:
7980
)
8081
else:
8182
# sync grpc returns metadata as a sequence of tuples
82-
metadata: Sequence[tuple[str.str | bytes]] = (
83-
source.trailing_metadata() + source.initial_metadata()
84-
)
83+
metadata = source.trailing_metadata() + source.initial_metadata()
8584
# convert metadata to dict format
86-
return {k: v for k, v in metadata}
85+
return {k: v for (k, v) in metadata}
8786
except Exception:
8887
# ignore errors while fetching metadata
8988
return None

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

Lines changed: 9 additions & 8 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 ClassVar, Tuple, cast, TYPE_CHECKING
16+
from typing import Callable, ClassVar, List, Tuple, Optional, cast, TYPE_CHECKING
1717

1818
import time
1919
import re
@@ -54,6 +54,11 @@
5454

5555
INVALID_STATE_ERROR = "Invalid state for {}: {}"
5656

57+
ExceptionFactoryType = Callable[
58+
[List[Exception], RetryFailureReason, Optional[float]],
59+
Tuple[Exception, Optional[Exception]],
60+
]
61+
5762

5863
class OperationType(Enum):
5964
"""Enum for the type of operation being performed."""
@@ -168,7 +173,7 @@ class ActiveOperationMetric:
168173
flow_throttling_time_ns: int = 0
169174

170175
_active_operation_context: ClassVar[
171-
contextvars.ContextVar
176+
contextvars.ContextVar[ActiveOperationMetric]
172177
] = contextvars.ContextVar("active_operation_context")
173178

174179
@classmethod
@@ -419,12 +424,8 @@ def track_retryable_error(self, exc: Exception) -> None:
419424
self.end_attempt_with_status(exc)
420425

421426
def track_terminal_error(
422-
self,
423-
exception_factory: callable[
424-
[list[Exception], RetryFailureReason, float | None],
425-
tuple[Exception, Exception | None],
426-
],
427-
) -> callable[[list[Exception], RetryFailureReason, float | None], None]:
427+
self, exception_factory: ExceptionFactoryType
428+
) -> ExceptionFactoryType:
428429
"""
429430
Used as input to api_core.Retry classes, to track when terminal errors are encountered
430431

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,8 @@ def __init__(
8484
self.is_retryable,
8585
metric.backoff_generator,
8686
operation_timeout,
87-
exception_factory=self._operation_metric.track_terminal_error(
88-
_retry_exception_factory
89-
),
90-
on_error=self._operation_metric.track_retryable_error,
87+
exception_factory=metric.track_terminal_error(_retry_exception_factory),
88+
on_error=metric.track_retryable_error,
9189
)
9290
self.timeout_generator = _attempt_timeout_generator(
9391
attempt_timeout, operation_timeout

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,6 @@ def merge_rows(
294294
raise close_exception
295295
except Exception as generic_exception:
296296
raise generic_exception
297-
else:
298-
self._operation_metric.end_with_success()
299297

300298
@staticmethod
301299
def _revise_request_rowset(row_set: RowSetPB, last_seen_row_key: bytes) -> RowSetPB:

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,8 @@ def wrapper(self, continuation, client_call_details, request):
4949
def _get_metadata(source) -> dict[str, str | bytes] | None:
5050
"""Helper to extract metadata from a call or RpcError"""
5151
try:
52-
metadata: Sequence[tuple[str.str | bytes]] = (
53-
source.trailing_metadata() + source.initial_metadata()
54-
)
52+
metadata: Sequence[tuple[str, str | bytes]]
53+
metadata = source.trailing_metadata() + source.initial_metadata()
5554
return {k: v for (k, v) in metadata}
5655
except Exception:
5756
return None

0 commit comments

Comments
 (0)