Skip to content

Commit

Permalink
fix: align layered annotations (#2913)
Browse files Browse the repository at this point in the history
* Align route handler decorator annotations with respective app/router/controller ones
* Align Controller annotations with Router
* Standardize the response_headers annotation
* Remove ResponseType type alias
  • Loading branch information
gsakkis authored and provinzkraut committed Feb 6, 2024
1 parent f81990b commit 1966c4d
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 100 deletions.
9 changes: 5 additions & 4 deletions litestar/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,13 @@
from litestar.config.compression import CompressionConfig
from litestar.config.cors import CORSConfig
from litestar.config.csrf import CSRFConfig
from litestar.datastructures import CacheControlHeader, ETag, ResponseHeader
from litestar.datastructures import CacheControlHeader, ETag
from litestar.dto import AbstractDTO
from litestar.events.listener import EventListener
from litestar.logging.config import BaseLoggingConfig
from litestar.openapi.spec import SecurityRequirement
from litestar.openapi.spec.open_api import OpenAPI
from litestar.response import Response
from litestar.static_files.config import StaticFilesConfig
from litestar.stores.base import Store
from litestar.types import (
Expand All @@ -91,7 +92,7 @@
ParametersMap,
Receive,
ResponseCookies,
ResponseType,
ResponseHeaders,
RouteHandlerType,
Scope,
Send,
Expand Down Expand Up @@ -203,9 +204,9 @@ def __init__(
plugins: Sequence[PluginProtocol] | None = None,
request_class: type[Request] | None = None,
response_cache_config: ResponseCacheConfig | None = None,
response_class: ResponseType | None = None,
response_class: type[Response] | None = None,
response_cookies: ResponseCookies | None = None,
response_headers: Sequence[ResponseHeader] | None = None,
response_headers: ResponseHeaders | None = None,
return_dto: type[AbstractDTO] | None | EmptyType = Empty,
security: Sequence[SecurityRequirement] | None = None,
signature_namespace: Mapping[str, Any] | None = None,
Expand Down
12 changes: 6 additions & 6 deletions litestar/config/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import enum
from dataclasses import dataclass, field
from typing import TYPE_CHECKING, Any, Callable, Sequence
from typing import TYPE_CHECKING, Any, Callable

from litestar.config.allowed_hosts import AllowedHostsConfig
from litestar.config.response_cache import ResponseCacheConfig
Expand All @@ -13,12 +13,12 @@
if TYPE_CHECKING:
from contextlib import AbstractAsyncContextManager

from litestar import Litestar
from litestar import Litestar, Response
from litestar.config.compression import CompressionConfig
from litestar.config.cors import CORSConfig
from litestar.config.csrf import CSRFConfig
from litestar.connection import Request, WebSocket
from litestar.datastructures import CacheControlHeader, ETag, ResponseHeader
from litestar.datastructures import CacheControlHeader, ETag
from litestar.di import Provide
from litestar.dto import AbstractDTO
from litestar.events.emitter import BaseEventEmitterBackend
Expand All @@ -43,7 +43,7 @@
Middleware,
ParametersMap,
ResponseCookies,
ResponseType,
ResponseHeaders,
TypeEncodersMap,
)
from litestar.types.callable_types import LifespanHook
Expand Down Expand Up @@ -157,11 +157,11 @@ class AppConfig:
"""List of :class:`SerializationPluginProtocol <.plugins.SerializationPluginProtocol>`."""
request_class: type[Request] | None = field(default=None)
"""An optional subclass of :class:`Request <.connection.Request>` to use for http connections."""
response_class: ResponseType | None = field(default=None)
response_class: type[Response] | None = field(default=None)
"""A custom subclass of :class:`Response <.response.Response>` to be used as the app's default response."""
response_cookies: ResponseCookies = field(default_factory=list)
"""A list of :class:`Cookie <.datastructures.Cookie>`."""
response_headers: Sequence[ResponseHeader] = field(default_factory=list)
response_headers: ResponseHeaders = field(default_factory=list)
"""A string keyed dictionary mapping :class:`ResponseHeader <.datastructures.ResponseHeader>`."""
response_cache_config: ResponseCacheConfig = field(default_factory=ResponseCacheConfig)
"""Configures caching behavior of the application."""
Expand Down
11 changes: 2 additions & 9 deletions litestar/handlers/http_handlers/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,7 @@
from litestar.background_tasks import BackgroundTask, BackgroundTasks
from litestar.connection import Request
from litestar.datastructures import Cookie, ResponseHeader
from litestar.types import (
AfterRequestHookHandler,
ASGIApp,
AsyncAnyCallable,
Method,
ResponseType,
TypeEncodersMap,
)
from litestar.types import AfterRequestHookHandler, ASGIApp, AsyncAnyCallable, Method, TypeEncodersMap
from litestar.typing import FieldDefinition

__all__ = (
Expand All @@ -42,7 +35,7 @@ def create_data_handler(
cookies: frozenset[Cookie],
headers: frozenset[ResponseHeader],
media_type: str,
response_class: ResponseType,
response_class: type[Response],
status_code: int,
type_encoders: TypeEncodersMap | None,
) -> AsyncAnyCallable:
Expand Down
3 changes: 1 addition & 2 deletions litestar/handlers/http_handlers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
Middleware,
ResponseCookies,
ResponseHeaders,
ResponseType,
TypeEncodersMap,
)
from litestar.utils import ensure_async_callable
Expand Down Expand Up @@ -135,7 +134,7 @@ def __init__(
middleware: Sequence[Middleware] | None = None,
name: str | None = None,
opt: Mapping[str, Any] | None = None,
response_class: ResponseType | None = None,
response_class: type[Response] | None = None,
response_cookies: ResponseCookies | None = None,
response_headers: ResponseHeaders | None = None,
return_dto: type[AbstractDTO] | None | EmptyType = Empty,
Expand Down
Loading

0 comments on commit 1966c4d

Please sign in to comment.