1313# limitations under the License.
1414from __future__ import annotations
1515
16- from typing import Callable , Tuple , cast , TYPE_CHECKING
16+ from typing import Tuple , cast , TYPE_CHECKING
1717
1818import time
1919import re
@@ -146,7 +146,9 @@ class ActiveOperationMetric:
146146 uuid : str = field (default_factory = lambda : str (uuid .uuid4 ()))
147147 # create a default backoff generator, initialized with standard default backoff values
148148 backoff_generator : TrackedBackoffGenerator = field (
149- default_factory = lambda : TrackedBackoffGenerator (initial = 0.01 , maximum = 60 , multiplier = 2 )
149+ default_factory = lambda : TrackedBackoffGenerator (
150+ initial = 0.01 , maximum = 60 , multiplier = 2
151+ )
150152 )
151153 # keep monotonic timestamps for active operations
152154 start_time_ns : int = field (default_factory = time .monotonic_ns )
@@ -187,7 +189,7 @@ def start(self) -> None:
187189 return self ._handle_error (INVALID_STATE_ERROR .format ("start" , self .state ))
188190 self .start_time_ns = time .monotonic_ns ()
189191
190- def start_attempt (self ) -> ActiveAttemptMetric :
192+ def start_attempt (self ) -> ActiveAttemptMetric | None :
191193 """
192194 Called to initiate a new attempt for the operation.
193195
@@ -204,9 +206,7 @@ def start_attempt(self) -> ActiveAttemptMetric:
204206 try :
205207 # find backoff value before this attempt
206208 prev_attempt_idx = len (self .completed_attempts ) - 1
207- backoff = self .backoff_generator .get_attempt_backoff (
208- prev_attempt_idx
209- )
209+ backoff = self .backoff_generator .get_attempt_backoff (prev_attempt_idx )
210210 # generator will return the backoff time in seconds, so convert to nanoseconds
211211 backoff_ns = int (backoff * 1e9 )
212212 except IndexError :
@@ -413,7 +413,7 @@ def _handle_error(message: str) -> None:
413413 full_message = f"Error in Bigtable Metrics: { message } "
414414 LOGGER .warning (full_message )
415415
416- def __aenter__ (self ):
416+ def __enter__ (self ):
417417 """
418418 Implements the async manager protocol
419419
@@ -423,7 +423,7 @@ def __aenter__(self):
423423 """
424424 return self
425425
426- def __aexit__ (self , exc_type , exc_val , exc_tb ):
426+ def __exit__ (self , exc_type , exc_val , exc_tb ):
427427 """
428428 Implements the context manager protocol
429429
0 commit comments