Skip to content
This repository was archived by the owner on Aug 19, 2025. It is now read-only.

Commit c877098

Browse files
authored
Improve typing for Transaction (#493)
1 parent fbea46d commit c877098

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

databases/core.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,9 @@ def _build_query(
315315
return query
316316

317317

318+
_CallableType = typing.TypeVar("_CallableType", bound=typing.Callable)
319+
320+
318321
class Transaction:
319322
def __init__(
320323
self,
@@ -347,13 +350,13 @@ async def __aexit__(
347350
else:
348351
await self.commit()
349352

350-
def __await__(self) -> typing.Generator:
353+
def __await__(self) -> typing.Generator[None, None, "Transaction"]:
351354
"""
352355
Called if using the low-level `transaction = await database.transaction()`
353356
"""
354357
return self.start().__await__()
355358

356-
def __call__(self, func: typing.Callable) -> typing.Callable:
359+
def __call__(self, func: _CallableType) -> _CallableType:
357360
"""
358361
Called if using `@database.transaction()` as a decorator.
359362
"""
@@ -363,7 +366,7 @@ async def wrapper(*args: typing.Any, **kwargs: typing.Any) -> typing.Any:
363366
async with self:
364367
return await func(*args, **kwargs)
365368

366-
return wrapper
369+
return wrapper # type: ignore
367370

368371
async def start(self) -> "Transaction":
369372
self._connection = self._connection_callable()

0 commit comments

Comments
 (0)