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

Add Generic Typing for decorate_view to resolve Pyright Issues #1126

Merged
merged 1 commit into from
Apr 30, 2024

Conversation

max-muoto
Copy link
Contributor

@max-muoto max-muoto commented Apr 12, 2024

For projects using Django Ninja that utilize Pyright, the typing for decorate_view leads to a reportUntypedFunctionDecorator error.

Let's take this example from the documentation:

from django.views.decorators.cache import cache_page

@api.get("/test")
@decorate_view(cache_page(5)) # Untyped function decorator obscures type of function
def test_view(request):
    return str(datetime.now())

By having decorate_view utilize generics, we can can avoid this. I also went about generally cleaning up the callable types, Callable[..., Any] is more descriptive than Callable. In Pyright the former would be preferred to avoid unknowns, as Callable == Callable[..., Unknown] instead of being Any. There have been times where I've imported private functions from ninja internals, while not often, it would be nice to avoid unknowns in these cases.

@max-muoto max-muoto force-pushed the fix-decorator-typing branch from b31f320 to 6bb47da Compare April 12, 2024 01:41
@max-muoto max-muoto force-pushed the fix-decorator-typing branch from 6bb47da to af88df5 Compare April 12, 2024 01:44
@max-muoto
Copy link
Contributor Author

@vitalik Was curious if there was anything else I could to help get this merged!

@vitalik vitalik merged commit e69baef into vitalik:master Apr 30, 2024
27 checks passed
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

Successfully merging this pull request may close these issues.

2 participants