|
13 | 13 | # limitations under the License. |
14 | 14 | from __future__ import annotations |
15 | 15 |
|
16 | | -from typing import ClassVar, Tuple, cast, TYPE_CHECKING |
| 16 | +from typing import Callable, ClassVar, List, Tuple, Optional, cast, TYPE_CHECKING |
17 | 17 |
|
18 | 18 | import time |
19 | 19 | import re |
|
54 | 54 |
|
55 | 55 | INVALID_STATE_ERROR = "Invalid state for {}: {}" |
56 | 56 |
|
| 57 | +ExceptionFactoryType = Callable[ |
| 58 | + [List[Exception], RetryFailureReason, Optional[float]], |
| 59 | + Tuple[Exception, Optional[Exception]], |
| 60 | +] |
| 61 | + |
57 | 62 |
|
58 | 63 | class OperationType(Enum): |
59 | 64 | """Enum for the type of operation being performed.""" |
@@ -168,7 +173,7 @@ class ActiveOperationMetric: |
168 | 173 | flow_throttling_time_ns: int = 0 |
169 | 174 |
|
170 | 175 | _active_operation_context: ClassVar[ |
171 | | - contextvars.ContextVar |
| 176 | + contextvars.ContextVar[ActiveOperationMetric] |
172 | 177 | ] = contextvars.ContextVar("active_operation_context") |
173 | 178 |
|
174 | 179 | @classmethod |
@@ -419,12 +424,8 @@ def track_retryable_error(self, exc: Exception) -> None: |
419 | 424 | self.end_attempt_with_status(exc) |
420 | 425 |
|
421 | 426 | 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: |
428 | 429 | """ |
429 | 430 | Used as input to api_core.Retry classes, to track when terminal errors are encountered |
430 | 431 |
|
|
0 commit comments