|
24 | 24 | Coroutine, |
25 | 25 | Optional, |
26 | 26 | TypeVar, |
27 | | - Concatenate, |
| 27 | + Protocol, |
28 | 28 | ) |
29 | 29 |
|
30 | | -try: |
31 | | - from typing import ParamSpec |
32 | | -except ImportError: |
33 | | - from typing_extensions import ParamSpec |
34 | | - |
35 | 30 | from google.api_core import exceptions, gapic_v1 |
36 | 31 | from google.api_core import retry_async as retries |
37 | 32 |
|
|
56 | 51 | from google.cloud.firestore_v1.query_profile import ExplainOptions |
57 | 52 |
|
58 | 53 |
|
59 | | -T = TypeVar("T") |
60 | | -P = ParamSpec("P") |
| 54 | +T = TypeVar("T", bound=Callable[..., Any]) |
61 | 55 |
|
62 | 56 |
|
63 | 57 | class AsyncTransaction(async_batch.AsyncWriteBatch, BaseTransaction): |
@@ -256,12 +250,12 @@ class _AsyncTransactional(_BaseTransactional): |
256 | 250 | """ |
257 | 251 |
|
258 | 252 | def __init__( |
259 | | - self, to_wrap: Callable[Concatenate[AsyncTransaction, P], Awaitable[T]] |
| 253 | + self, to_wrap: Callable[..., Awaitable[T]] |
260 | 254 | ) -> None: |
261 | 255 | super(_AsyncTransactional, self).__init__(to_wrap) |
262 | 256 |
|
263 | 257 | async def _pre_commit( |
264 | | - self, transaction: AsyncTransaction, *args: P.args, **kwargs: P.kwargs |
| 258 | + self, transaction: AsyncTransaction, *args: Any, **kwargs: Any |
265 | 259 | ) -> Coroutine: |
266 | 260 | """Begin transaction and call the wrapped coroutine. |
267 | 261 |
|
@@ -291,7 +285,7 @@ async def _pre_commit( |
291 | 285 | return await self.to_wrap(transaction, *args, **kwargs) |
292 | 286 |
|
293 | 287 | async def __call__( |
294 | | - self, transaction: AsyncTransaction, *args: P.args, **kwargs: P.kwargs |
| 288 | + self, transaction: AsyncTransaction, *args: Any, **kwargs: Any |
295 | 289 | ) -> T: |
296 | 290 | """Execute the wrapped callable within a transaction. |
297 | 291 |
|
@@ -343,9 +337,12 @@ async def __call__( |
343 | 337 | raise |
344 | 338 |
|
345 | 339 |
|
| 340 | +class WithAsyncTransaction(Protocol[T]): |
| 341 | + def __call__(self, transaction: AsyncTransaction, *args: Any, **kwargs: Any) -> Awaitable[T]: ... |
| 342 | + |
346 | 343 | def async_transactional( |
347 | | - to_wrap: Callable[Concatenate[AsyncTransaction, P], Awaitable[T]] |
348 | | -) -> Callable[Concatenate[AsyncTransaction, P], Awaitable[T]]: |
| 344 | + to_wrap: Callable[..., Awaitable[T]] |
| 345 | +) -> WithAsyncTransaction[T]: |
349 | 346 | """Decorate a callable so that it runs in a transaction. |
350 | 347 |
|
351 | 348 | Args: |
|
0 commit comments