3939from google .cloud .firestore_v1 .async_document import AsyncDocumentReference
4040from google .cloud .firestore_v1 .async_document import DocumentSnapshot
4141from google .cloud .firestore_v1 .async_query import AsyncQuery
42- from typing import Any , AsyncGenerator , Coroutine
42+ from typing import Any , AsyncGenerator , Callable , Coroutine
43+
44+ # Types needed only for Type Hints
45+ from google .cloud .firestore_v1 .client import Client
4346
4447
4548class AsyncTransaction (async_batch .AsyncWriteBatch , BaseTransaction ):
@@ -60,7 +63,7 @@ def __init__(self, client, max_attempts=MAX_ATTEMPTS, read_only=False) -> None:
6063 super (AsyncTransaction , self ).__init__ (client )
6164 BaseTransaction .__init__ (self , max_attempts , read_only )
6265
63- def _add_write_pbs (self , write_pbs ) -> None :
66+ def _add_write_pbs (self , write_pbs : list ) -> None :
6467 """Add `Write`` protobufs to this transaction.
6568
6669 Args:
@@ -75,7 +78,7 @@ def _add_write_pbs(self, write_pbs) -> None:
7578
7679 super (AsyncTransaction , self )._add_write_pbs (write_pbs )
7780
78- async def _begin (self , retry_id = None ) -> None :
81+ async def _begin (self , retry_id : bytes = None ) -> None :
7982 """Begin the transaction.
8083
8184 Args:
@@ -141,7 +144,7 @@ async def _commit(self) -> list:
141144 self ._clean_up ()
142145 return list (commit_response .write_results )
143146
144- async def get_all (self , references ) -> Coroutine :
147+ async def get_all (self , references : list ) -> Coroutine :
145148 """Retrieves multiple documents from Firestore.
146149
147150 Args:
@@ -187,7 +190,9 @@ class _AsyncTransactional(_BaseTransactional):
187190 def __init__ (self , to_wrap ) -> None :
188191 super (_AsyncTransactional , self ).__init__ (to_wrap )
189192
190- async def _pre_commit (self , transaction , * args , ** kwargs ) -> Coroutine :
193+ async def _pre_commit (
194+ self , transaction : AsyncTransaction , * args , ** kwargs
195+ ) -> Coroutine :
191196 """Begin transaction and call the wrapped coroutine.
192197
193198 If the coroutine raises an exception, the transaction will be rolled
@@ -225,7 +230,7 @@ async def _pre_commit(self, transaction, *args, **kwargs) -> Coroutine:
225230 await transaction ._rollback ()
226231 raise
227232
228- async def _maybe_commit (self , transaction ) -> bool :
233+ async def _maybe_commit (self , transaction : AsyncTransaction ) -> bool :
229234 """Try to commit the transaction.
230235
231236 If the transaction is read-write and the ``Commit`` fails with the
@@ -291,7 +296,9 @@ async def __call__(self, transaction, *args, **kwargs):
291296 raise ValueError (msg )
292297
293298
294- def async_transactional (to_wrap ) -> _AsyncTransactional :
299+ def async_transactional (
300+ to_wrap : Callable [[AsyncTransaction ], Any ]
301+ ) -> _AsyncTransactional :
295302 """Decorate a callable so that it runs in a transaction.
296303
297304 Args:
@@ -307,7 +314,9 @@ def async_transactional(to_wrap) -> _AsyncTransactional:
307314
308315
309316# TODO(crwilcox): this was 'coroutine' from pytype merge-pyi...
310- async def _commit_with_retry (client , write_pbs , transaction_id ) -> types .CommitResponse :
317+ async def _commit_with_retry (
318+ client : Client , write_pbs : list , transaction_id : bytes
319+ ) -> types .CommitResponse :
311320 """Call ``Commit`` on the GAPIC client with retry / sleep.
312321
313322 Retries the ``Commit`` RPC on Unavailable. Usually this RPC-level
@@ -350,7 +359,9 @@ async def _commit_with_retry(client, write_pbs, transaction_id) -> types.CommitR
350359 current_sleep = await _sleep (current_sleep )
351360
352361
353- async def _sleep (current_sleep , max_sleep = _MAX_SLEEP , multiplier = _MULTIPLIER ) -> float :
362+ async def _sleep (
363+ current_sleep : float , max_sleep : float = _MAX_SLEEP , multiplier : float = _MULTIPLIER
364+ ) -> float :
354365 """Sleep and produce a new sleep time.
355366
356367 .. _Exponential Backoff And Jitter: https://www.awsarchitectureblog.com/\
0 commit comments