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

Sample code has pyright type checking issues #106

Open
skewty opened this issue Jun 21, 2024 · 1 comment
Open

Sample code has pyright type checking issues #106

skewty opened this issue Jun 21, 2024 · 1 comment

Comments

@skewty
Copy link

skewty commented Jun 21, 2024

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?

@skewty
Copy link
Author

skewty commented Jun 22, 2024

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant