From 885f8c15921173bca21e887bce835b1e1b96fa97 Mon Sep 17 00:00:00 2001 From: Orhan Hirsch Date: Wed, 11 Jan 2023 15:58:36 +0100 Subject: [PATCH] Simplify method_router types --- django_api_decorator/utils.py | 6 +++--- pyproject.toml | 2 +- tests/test_method_router.py | 6 +++++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/django_api_decorator/utils.py b/django_api_decorator/utils.py index 4802a79..0f9394b 100644 --- a/django_api_decorator/utils.py +++ b/django_api_decorator/utils.py @@ -7,8 +7,8 @@ def method_router( csrf_exempt: bool | None = None, - **views: Callable[Concatenate[HttpRequest, P], HttpResponse], -) -> Callable[Concatenate[HttpRequest, P], HttpResponse]: + **views: Callable[..., HttpResponse], +) -> Callable[..., HttpResponse]: """ Returns a view that dispatches to different views based on the request method. This allows us to have plain function views for each HTTP method, rather than @@ -57,4 +57,4 @@ def call_view( call_view._method_router_views = views # type: ignore[attr-defined] - return cast(Callable[Concatenate[HttpRequest, P], HttpResponse], call_view) + return cast(Callable[..., HttpResponse], call_view) diff --git a/pyproject.toml b/pyproject.toml index d2dce7c..01fef2b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "django-api-decorator" -version = "0.1.3" +version = "0.1.4" description = "A collection of tools to build function based Django APIs" authors = ["Oda "] license = "MIT" diff --git a/tests/test_method_router.py b/tests/test_method_router.py index f4d6922..3bc6ae5 100644 --- a/tests/test_method_router.py +++ b/tests/test_method_router.py @@ -4,6 +4,7 @@ from django.test.client import Client from django.test.utils import override_settings from django.urls import path +from pydantic import BaseModel from django_api_decorator.decorators import api from django_api_decorator.utils import method_router @@ -17,8 +18,11 @@ def test_allowed_methods(client: Client) -> None: def get_view(request: HttpRequest) -> JsonResponse: return JsonResponse({"data": True}) + class Body(BaseModel): + name: str + @api(method="POST", login_required=False) - def post_view(request: HttpRequest) -> JsonResponse: + def post_view(request: HttpRequest, body: Body) -> JsonResponse: return JsonResponse({"data": True}) urls = [