Skip to content

Commit 576a8a8

Browse files
committed
use a protocol
1 parent a630701 commit 576a8a8

File tree

2 files changed

+10
-14
lines changed

2 files changed

+10
-14
lines changed

google/cloud/firestore_v1/async_transaction.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,9 @@
2424
Coroutine,
2525
Optional,
2626
TypeVar,
27-
Concatenate,
27+
Protocol,
2828
)
2929

30-
try:
31-
from typing import ParamSpec
32-
except ImportError:
33-
from typing_extensions import ParamSpec
34-
3530
from google.api_core import exceptions, gapic_v1
3631
from google.api_core import retry_async as retries
3732

@@ -56,8 +51,7 @@
5651
from google.cloud.firestore_v1.query_profile import ExplainOptions
5752

5853

59-
T = TypeVar("T")
60-
P = ParamSpec("P")
54+
T = TypeVar("T", bound=Callable[..., Any])
6155

6256

6357
class AsyncTransaction(async_batch.AsyncWriteBatch, BaseTransaction):
@@ -256,12 +250,12 @@ class _AsyncTransactional(_BaseTransactional):
256250
"""
257251

258252
def __init__(
259-
self, to_wrap: Callable[Concatenate[AsyncTransaction, P], Awaitable[T]]
253+
self, to_wrap: Callable[..., Awaitable[T]]
260254
) -> None:
261255
super(_AsyncTransactional, self).__init__(to_wrap)
262256

263257
async def _pre_commit(
264-
self, transaction: AsyncTransaction, *args: P.args, **kwargs: P.kwargs
258+
self, transaction: AsyncTransaction, *args: Any, **kwargs: Any
265259
) -> Coroutine:
266260
"""Begin transaction and call the wrapped coroutine.
267261
@@ -291,7 +285,7 @@ async def _pre_commit(
291285
return await self.to_wrap(transaction, *args, **kwargs)
292286

293287
async def __call__(
294-
self, transaction: AsyncTransaction, *args: P.args, **kwargs: P.kwargs
288+
self, transaction: AsyncTransaction, *args: Any, **kwargs: Any
295289
) -> T:
296290
"""Execute the wrapped callable within a transaction.
297291
@@ -343,9 +337,12 @@ async def __call__(
343337
raise
344338

345339

340+
class WithAsyncTransaction(Protocol[T]):
341+
def __call__(self, transaction: AsyncTransaction, *args: Any, **kwargs: Any) -> Awaitable[T]: ...
342+
346343
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]:
349346
"""Decorate a callable so that it runs in a transaction.
350347
351348
Args:

setup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
"proto-plus >= 1.22.2, <2.0.0; python_version>='3.11'",
4040
"proto-plus >= 1.25.0, <2.0.0; python_version>='3.13'",
4141
"protobuf>=3.20.2,<7.0.0dev,!=3.20.0,!=3.20.1,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5",
42-
"typing_extensions>=4.13, <5; python_version<'3.10'",
4342
]
4443
extras = {}
4544

0 commit comments

Comments
 (0)