Lancetnik/FastDepends

Sample code has pyright type checking issues

Opened this issue · 1 comments

from typing import Annotated

from fast_depends import Depends, Provider, inject

provider = Provider()


def abc_func() -> int:
    raise NotImplementedError


def real_func() -> int:
    return 1


@inject(dependency_overrides_provider=provider)  # pyright: ignore [reportCallIssue]
def func(dependency: Annotated[int, Depends(abc_func)]) -> int:
    return dependency


with provider.scope(abc_func, real_func):
    assert func() == 1  # pyright: ignore [reportCallIssue]

I added the pyright ignore comments to make pyright happy. Can the signatures be adjusted to alleviate this usability issue?

I get how

@inject(dependency_overrides_provider=provider)  # pyright: ignore [reportCallIssue]
def func(dependency: int = Depends(abc_func)) -> int:
   return dependency

fixes one of them. It is perhaps wise to ensure this is the recommended way in the documentation and why it is the recommended way (an explanation of the troubles one may encounter if using just Annotation).

That just leaves the type hinting of inject which seems to need some adjustment to appease pyright (haven't tried mypy against it yet).