Skip to content

Commit 098c0d1

Browse files
committed
fixup! fixup! fixup! Add django decorator
1 parent c3e4c1b commit 098c0d1

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

openapi_core/contrib/django/decorators.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
"""OpenAPI core contrib django decorators module"""
22

3+
from typing import Any
4+
from typing import Callable
5+
from typing import Optional
36
from typing import Type
47

58
from django.conf import settings
@@ -26,7 +29,7 @@ class DjangoOpenAPIViewDecorator(DjangoIntegration):
2629

2730
def __init__(
2831
self,
29-
openapi: OpenAPI == None,
32+
openapi: Optional[OpenAPI] = None,
3033
request_cls: Type[DjangoOpenAPIRequest] = DjangoOpenAPIRequest,
3134
response_cls: Type[DjangoOpenAPIResponse] = DjangoOpenAPIResponse,
3235
errors_handler_cls: Type[
@@ -46,7 +49,7 @@ def __init__(
4649
self.request_cls = request_cls
4750
self.response_cls = response_cls
4851

49-
def __call__(self, view_func):
52+
def __call__(self, view_func: Callable[..., Any]) -> Callable[..., Any]:
5053
"""
5154
Thanks to this method, the class acts as a decorator.
5255
Example usage:
@@ -57,7 +60,7 @@ def my_view(request): ...
5760
"""
5861

5962
def _wrapped_view(
60-
request: HttpRequest, *args, **kwargs
63+
request: HttpRequest, *args: Any, **kwargs: Any
6164
) -> HttpResponse:
6265
# get_response is the function that we treats
6366
# as the "next step" in the chain (i.e., our original view).

openapi_core/contrib/django/providers.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""OpenAPI core contrib django providers module"""
22

33
import warnings
4+
from typing import cast
45

56
from django.conf import settings
67
from django.core.exceptions import ImproperlyConfigured
@@ -16,7 +17,7 @@ def get_default_openapi_instance() -> OpenAPI:
1617
"""
1718
if hasattr(settings, "OPENAPI"):
1819
# Recommended (newer) approach
19-
return settings.OPENAPI
20+
return cast(OpenAPI, settings.OPENAPI)
2021
elif hasattr(settings, "OPENAPI_SPEC"):
2122
# Backward compatibility
2223
warnings.warn(

0 commit comments

Comments
 (0)