Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix container getter return type #46

Merged
merged 4 commits into from
Feb 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 34 additions & 2 deletions src/dishka/integrations/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@
from typing import (
Annotated,
Any,
Awaitable,
Callable,
Literal,
Sequence,
Type,
get_args,
get_origin,
get_type_hints,
overload,
)

from dishka.async_container import AsyncContainer
from dishka.container import Container


Expand All @@ -20,7 +25,7 @@ def __init__(self, param: Any = None):
def default_parse_dependency(
parameter: Parameter,
hint: Any,
depends_class: Any = Depends,
depends_class: Type[Any] = Depends,
) -> Any:
""" Resolve dependency type or return None if it is not a dependency """
if get_origin(hint) is not Annotated:
Expand All @@ -40,14 +45,41 @@ def default_parse_dependency(
DependencyParser = Callable[[Parameter, Any], Any]


@overload
def wrap_injection(
*,
func: Callable,
container_getter: Callable[[tuple, dict], Container],
is_async: Literal[False] = False,
remove_depends: bool = True,
additional_params: Sequence[Parameter] = (),
is_async: bool = False,
parse_dependency: DependencyParser = default_parse_dependency,
) -> Callable:
...


@overload
def wrap_injection(
*,
func: Callable,
container_getter: Callable[[tuple, dict], AsyncContainer],
is_async: Literal[True],
remove_depends: bool = True,
additional_params: Sequence[Parameter] = (),
parse_dependency: DependencyParser = default_parse_dependency,
) -> Awaitable:
...


def wrap_injection(
*,
func: Callable,
container_getter,
is_async: bool = False,
remove_depends: bool = True,
additional_params: Sequence[Parameter] = (),
parse_dependency: DependencyParser = default_parse_dependency,
):
hints = get_type_hints(func, include_extras=True)
func_signature = signature(func)

Expand Down
Loading