-
Notifications
You must be signed in to change notification settings - Fork 264
Closed
Description
Hi! I've noticed several places
Transaction.__call__
Right now it is defined as:
def __call__(self, func: typing.Callable) -> typing.Callable:
"""
Called if using `@database.transaction()` as a decorator.
"""
@functools.wraps(func)
async def wrapper(*args: typing.Any, **kwargs: typing.Any) -> typing.Any:
async with self:
return await func(*args, **kwargs)
return wrapper
Lines 356 to 366 in fbea46d
def __call__(self, func: typing.Callable) -> typing.Callable: | |
""" | |
Called if using `@database.transaction()` as a decorator. | |
""" | |
@functools.wraps(func) | |
async def wrapper(*args: typing.Any, **kwargs: typing.Any) -> typing.Any: | |
async with self: | |
return await func(*args, **kwargs) | |
return wrapper |
Which make all wrapped function to have (*Any, **Any) -> Any
type. This is not ideal.
I propose to use TypeVar('_CallableType', bound=Callable)
to save the exact type.
After:
from databases import Database
db = Database('url')
async def test(a: int) -> int:
...
reveal_type(db.transaction()(test))
# note: Revealed type is "def (a: builtins.int) -> typing.Coroutine[Any, Any, builtins.int]"
Notice, that signature is preserved.
Transaction.__await__
Right now there's a small problem with it:
from databases import Database
db = Database('url')
async def test() -> None:
reveal_type(await db.transaction())
# note: Revealed type is "Any"
# But, should be the same as the next line:
reveal_type(await db.transaction().start())
# note: Revealed type is "databases.core.Transaction"
I propose to use the same type for await db.transaction()
Metadata
Metadata
Assignees
Labels
No labels