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

Commit f47e606

Browse files
committed
mypy
1 parent cd2cc45 commit f47e606

3 files changed

Lines changed: 20 additions & 13 deletions

File tree

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#
1515
from __future__ import annotations
1616

17-
from typing import Sequence, TYPE_CHECKING, cast
17+
from typing import Callable, Optional, Sequence, TYPE_CHECKING, cast
1818
import atexit
1919
import warnings
2020
from collections import deque
@@ -276,7 +276,9 @@ def __init__(
276276
self._newest_exceptions: deque[Exception] = deque(
277277
maxlen=self._exception_list_limit
278278
)
279-
self._user_batch_completed_callback = None
279+
self._user_batch_completed_callback: Optional[
280+
Callable[[list[status_pb2.Status]], None]
281+
] = None
280282
# clean up on program exit
281283
atexit.register(self._on_exit)
282284

google/cloud/bigtable/data/_helpers.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"""
1717
from __future__ import annotations
1818

19-
from typing import Callable, Sequence, List, Optional, Tuple, TYPE_CHECKING, Union
19+
from typing import cast, Callable, Sequence, List, Optional, Tuple, TYPE_CHECKING, Union
2020
import time
2121
import enum
2222
from collections import namedtuple
@@ -272,14 +272,17 @@ def _get_status(exc: Optional[Exception]) -> status_pb2.Status:
272272
Returns:
273273
status_pb2.Status: A Status proto object.
274274
"""
275-
if (
276-
isinstance(exc, core_exceptions.GoogleAPICallError)
277-
and exc.grpc_status_code is not None
278-
):
279-
return status_pb2.Status( # type: ignore[unreachable]
280-
code=exc.grpc_status_code.value[0],
281-
message=exc.message,
282-
details=exc.details,
275+
if isinstance(exc, core_exceptions.GoogleAPICallError):
276+
status_code = cast(Optional["grpc.StatusCode"], exc.grpc_status_code)
277+
if status_code is not None:
278+
return status_pb2.Status(
279+
code=status_code.value[0],
280+
message=exc.message,
281+
details=exc.details,
282+
)
283+
return status_pb2.Status(
284+
code=code_pb2.Code.UNKNOWN,
285+
message="An unknown error has occurred",
283286
)
284287

285288
return status_pb2.Status(

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# This file is automatically generated by CrossSync. Do not edit manually.
1717

1818
from __future__ import annotations
19-
from typing import Sequence, TYPE_CHECKING, cast
19+
from typing import Callable, Optional, Sequence, TYPE_CHECKING, cast
2020
import atexit
2121
import warnings
2222
from collections import deque
@@ -238,7 +238,9 @@ def __init__(
238238
self._newest_exceptions: deque[Exception] = deque(
239239
maxlen=self._exception_list_limit
240240
)
241-
self._user_batch_completed_callback = None
241+
self._user_batch_completed_callback: Optional[
242+
Callable[[list[status_pb2.Status]], None]
243+
] = None
242244
atexit.register(self._on_exit)
243245

244246
def _timer_routine(self, interval: float | None) -> None:

0 commit comments

Comments
 (0)