diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 60f2b1e01c..32edb3fa67 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -23,8 +23,8 @@ repos: hooks: - id: unasyncd additional_dependencies: ["ruff"] - - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: "v0.7.4" + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: "v0.8.0" hooks: - id: ruff args: ["--fix"] diff --git a/litestar/_kwargs/cleanup.py b/litestar/_kwargs/cleanup.py index 8839d360df..12e5f31af4 100644 --- a/litestar/_kwargs/cleanup.py +++ b/litestar/_kwargs/cleanup.py @@ -24,7 +24,7 @@ class DependencyCleanupGroup: exceptions caught in this manner will be re-raised after they have been thrown in the generators. """ - __slots__ = ("_generators", "_closed") + __slots__ = ("_closed", "_generators") def __init__(self, generators: list[AnyGenerator] | None = None) -> None: """Initialize ``DependencyCleanupGroup``. diff --git a/litestar/_kwargs/dependencies.py b/litestar/_kwargs/dependencies.py index bd3eb1b33c..8f5accede8 100644 --- a/litestar/_kwargs/dependencies.py +++ b/litestar/_kwargs/dependencies.py @@ -16,7 +16,7 @@ class Dependency: """Dependency graph of a given combination of ``Route`` + ``RouteHandler``""" - __slots__ = ("key", "provide", "dependencies") + __slots__ = ("dependencies", "key", "provide") def __init__(self, key: str, provide: Provide, dependencies: list[Dependency]) -> None: """Initialize a dependency. diff --git a/litestar/_openapi/plugin.py b/litestar/_openapi/plugin.py index 96eb80afa7..78349b7e3f 100644 --- a/litestar/_openapi/plugin.py +++ b/litestar/_openapi/plugin.py @@ -53,11 +53,11 @@ def handle_schema_path_not_found(path: str = "/") -> Response: class OpenAPIPlugin(InitPluginProtocol, ReceiveRoutePlugin): __slots__ = ( - "app", - "included_routes", - "_openapi_config", "_openapi", + "_openapi_config", "_openapi_schema", + "app", + "included_routes", ) def __init__(self, app: Litestar) -> None: diff --git a/litestar/_openapi/schema_generation/utils.py b/litestar/_openapi/schema_generation/utils.py index 832952cb79..cfcb976c82 100644 --- a/litestar/_openapi/schema_generation/utils.py +++ b/litestar/_openapi/schema_generation/utils.py @@ -12,9 +12,9 @@ from litestar.typing import FieldDefinition __all__ = ( - "_type_or_first_not_none_inner_type", "_should_create_enum_schema", "_should_create_literal_schema", + "_type_or_first_not_none_inner_type", ) @@ -75,9 +75,8 @@ def _should_create_literal_schema(field_definition: FieldDefinition) -> bool: Returns: A boolean """ - return ( - field_definition.is_literal - or field_definition.is_optional + return field_definition.is_literal or ( + field_definition.is_optional and all(inner.is_literal for inner in field_definition.inner_types if not inner.is_none_type) ) diff --git a/litestar/_openapi/utils.py b/litestar/_openapi/utils.py index b1950fa0be..aadc67b3bc 100644 --- a/litestar/_openapi/utils.py +++ b/litestar/_openapi/utils.py @@ -10,7 +10,7 @@ from litestar.types import Method -__all__ = ("default_operation_id_creator", "SEPARATORS_CLEANUP_PATTERN") +__all__ = ("SEPARATORS_CLEANUP_PATTERN", "default_operation_id_creator") SEPARATORS_CLEANUP_PATTERN = re.compile(r"[!#$%&'*+\-.^_`|~:]+") diff --git a/litestar/_signature/utils.py b/litestar/_signature/utils.py index 8c0d15fe2b..c0156450df 100644 --- a/litestar/_signature/utils.py +++ b/litestar/_signature/utils.py @@ -12,7 +12,7 @@ from litestar.utils.signature import ParsedSignature -__all__ = ("_validate_signature_dependencies", "_normalize_annotation", "_get_decoder_for_type") +__all__ = ("_get_decoder_for_type", "_normalize_annotation", "_validate_signature_dependencies") def _validate_signature_dependencies( diff --git a/litestar/app.py b/litestar/app.py index 62983388ec..399c01dc03 100644 --- a/litestar/app.py +++ b/litestar/app.py @@ -103,7 +103,7 @@ from litestar.types.callable_types import LifespanHook -__all__ = ("HandlerIndex", "Litestar", "DEFAULT_OPENAPI_CONFIG") +__all__ = ("DEFAULT_OPENAPI_CONFIG", "HandlerIndex", "Litestar") DEFAULT_OPENAPI_CONFIG = OpenAPIConfig(title="Litestar API", version="1.0.0") """The default OpenAPI config used if not configuration is explicitly passed to the @@ -136,12 +136,11 @@ class Litestar(Router): """ __slots__ = ( - "_lifespan_managers", - "_server_lifespan_managers", "_debug", + "_lifespan_managers", "_openapi_schema", + "_server_lifespan_managers", "_static_files_config", - "plugins", "after_exception", "allowed_hosts", "asgi_handler", @@ -151,6 +150,7 @@ class Litestar(Router): "cors_config", "csrf_config", "event_emitter", + "experimental_features", "get_logger", "logger", "logging_config", @@ -158,13 +158,13 @@ class Litestar(Router): "on_shutdown", "on_startup", "openapi_config", + "pdb_on_exception", + "plugins", "response_cache_config", "route_map", "state", "stores", "template_engine", - "pdb_on_exception", - "experimental_features", ) def __init__( diff --git a/litestar/background_tasks.py b/litestar/background_tasks.py index a47583603b..4e5182e567 100644 --- a/litestar/background_tasks.py +++ b/litestar/background_tasks.py @@ -17,7 +17,7 @@ class BackgroundTask: Background tasks are called once a Response finishes. """ - __slots__ = ("fn", "args", "kwargs") + __slots__ = ("args", "fn", "kwargs") def __init__(self, fn: Callable[P, Any], *args: P.args, **kwargs: P.kwargs) -> None: """Initialize ``BackgroundTask``. @@ -46,7 +46,7 @@ class BackgroundTasks: Background tasks are called once a Response finishes. """ - __slots__ = ("tasks", "run_in_task_group") + __slots__ = ("run_in_task_group", "tasks") def __init__(self, tasks: Iterable[BackgroundTask], run_in_task_group: bool = False) -> None: """Initialize ``BackgroundTasks``. diff --git a/litestar/channels/__init__.py b/litestar/channels/__init__.py index 0167223ddb..d6fefec6c9 100644 --- a/litestar/channels/__init__.py +++ b/litestar/channels/__init__.py @@ -2,4 +2,4 @@ from .plugin import ChannelsPlugin from .subscriber import Subscriber -__all__ = ("ChannelsPlugin", "ChannelsBackend", "Subscriber") +__all__ = ("ChannelsBackend", "ChannelsPlugin", "Subscriber") diff --git a/litestar/cli/_utils.py b/litestar/cli/_utils.py index 41494bc5d1..c6542c1b32 100644 --- a/litestar/cli/_utils.py +++ b/litestar/cli/_utils.py @@ -47,13 +47,13 @@ __all__ = ( - "UVICORN_INSTALLED", "JSBEAUTIFIER_INSTALLED", - "LoadedApp", + "UVICORN_INSTALLED", "LitestarCLIException", "LitestarEnv", "LitestarExtensionGroup", "LitestarGroup", + "LoadedApp", "show_app_info", ) diff --git a/litestar/concurrency.py b/litestar/concurrency.py index 90eadbf724..f9e2051dfb 100644 --- a/litestar/concurrency.py +++ b/litestar/concurrency.py @@ -19,11 +19,11 @@ __all__ = ( - "sync_to_thread", - "set_asyncio_executor", "get_asyncio_executor", - "set_trio_capacity_limiter", "get_trio_capacity_limiter", + "set_asyncio_executor", + "set_trio_capacity_limiter", + "sync_to_thread", ) diff --git a/litestar/config/response_cache.py b/litestar/config/response_cache.py index 4f1dfe9698..8392f5b2d9 100644 --- a/litestar/config/response_cache.py +++ b/litestar/config/response_cache.py @@ -17,7 +17,7 @@ from litestar.stores.base import Store from litestar.types import CacheKeyBuilder, HTTPScope -__all__ = ("ResponseCacheConfig", "default_cache_key_builder", "CACHE_FOREVER") +__all__ = ("CACHE_FOREVER", "ResponseCacheConfig", "default_cache_key_builder") @final diff --git a/litestar/connection/base.py b/litestar/connection/base.py index d14c6620e5..6c80e96522 100644 --- a/litestar/connection/base.py +++ b/litestar/connection/base.py @@ -57,15 +57,15 @@ class ASGIConnection(Generic[HandlerT, UserT, AuthT, StateT]): """The base ASGI connection container.""" __slots__ = ( - "scope", - "receive", - "send", "_base_url", - "_url", - "_parsed_query", + "_connection_state", "_cookies", + "_parsed_query", "_server_extensions", - "_connection_state", + "_url", + "receive", + "scope", + "send", ) scope: Scope diff --git a/litestar/connection/request.py b/litestar/connection/request.py index e76054b042..d874586b7f 100644 --- a/litestar/connection/request.py +++ b/litestar/connection/request.py @@ -49,13 +49,13 @@ class Request(Generic[UserT, AuthT, StateT], ASGIConnection["HTTPRouteHandler", """The Litestar Request class.""" __slots__ = ( - "_json", - "_form", - "_body", - "_msgpack", - "_content_type", "_accept", + "_body", "_content_length", + "_content_type", + "_form", + "_json", + "_msgpack", "is_connected", "supports_push_promise", ) diff --git a/litestar/contrib/htmx/_utils.py b/litestar/contrib/htmx/_utils.py index b44bb2c7eb..a313c24ce6 100644 --- a/litestar/contrib/htmx/_utils.py +++ b/litestar/contrib/htmx/_utils.py @@ -5,7 +5,7 @@ from litestar.utils import warn_deprecation if TYPE_CHECKING: - from litestar_htmx._utils import ( # noqa: TCH004 + from litestar_htmx._utils import ( # noqa: TC004 HTMXHeaders, get_headers, get_location_headers, diff --git a/litestar/contrib/htmx/request.py b/litestar/contrib/htmx/request.py index 4efff1ae76..54c7fb7fa5 100644 --- a/litestar/contrib/htmx/request.py +++ b/litestar/contrib/htmx/request.py @@ -5,7 +5,7 @@ from litestar.utils import warn_deprecation if TYPE_CHECKING: - from litestar_htmx import ( # noqa: TCH004 + from litestar_htmx import ( # noqa: TC004 HTMXDetails, HTMXRequest, ) diff --git a/litestar/contrib/htmx/response.py b/litestar/contrib/htmx/response.py index 9daca30339..aa1abd5fc1 100644 --- a/litestar/contrib/htmx/response.py +++ b/litestar/contrib/htmx/response.py @@ -5,7 +5,7 @@ from litestar.utils import warn_deprecation if TYPE_CHECKING: - from litestar_htmx import ( # noqa: TCH004 + from litestar_htmx import ( # noqa: TC004 ClientRedirect, ClientRefresh, HTMXTemplate, diff --git a/litestar/contrib/htmx/types.py b/litestar/contrib/htmx/types.py index 5cb7a8ed4e..a83806ed69 100644 --- a/litestar/contrib/htmx/types.py +++ b/litestar/contrib/htmx/types.py @@ -5,7 +5,7 @@ from litestar.utils import warn_deprecation if TYPE_CHECKING: - from litestar_htmx import HtmxHeaderType, LocationType, TriggerEventType # noqa: TCH004 + from litestar_htmx import HtmxHeaderType, LocationType, TriggerEventType # noqa: TC004 __all__ = ( "HtmxHeaderType", "LocationType", diff --git a/litestar/contrib/opentelemetry/plugin.py b/litestar/contrib/opentelemetry/plugin.py index b8f60d6d5b..39c84afc46 100644 --- a/litestar/contrib/opentelemetry/plugin.py +++ b/litestar/contrib/opentelemetry/plugin.py @@ -15,7 +15,7 @@ class OpenTelemetryPlugin(InitPluginProtocol): """OpenTelemetry Plugin.""" - __slots__ = ("config", "_middleware") + __slots__ = ("_middleware", "config") def __init__(self, config: OpenTelemetryConfig | None = None) -> None: self.config = config or OpenTelemetryConfig() diff --git a/litestar/contrib/prometheus/__init__.py b/litestar/contrib/prometheus/__init__.py index bedeec9976..6224668bef 100644 --- a/litestar/contrib/prometheus/__init__.py +++ b/litestar/contrib/prometheus/__init__.py @@ -5,7 +5,7 @@ from litestar.utils import warn_deprecation -__all__ = ("PrometheusMiddleware", "PrometheusConfig", "PrometheusController") +__all__ = ("PrometheusConfig", "PrometheusController", "PrometheusMiddleware") def __getattr__(attr_name: str) -> object: diff --git a/litestar/contrib/pydantic/__init__.py b/litestar/contrib/pydantic/__init__.py index 66a42f47cc..3ca7a6e9ed 100644 --- a/litestar/contrib/pydantic/__init__.py +++ b/litestar/contrib/pydantic/__init__.py @@ -6,11 +6,11 @@ from litestar.utils import warn_deprecation __all__ = ( + "PydanticDIPlugin", "PydanticDTO", "PydanticInitPlugin", - "PydanticSchemaPlugin", "PydanticPlugin", - "PydanticDIPlugin", + "PydanticSchemaPlugin", ) diff --git a/litestar/contrib/sqlalchemy/__init__.py b/litestar/contrib/sqlalchemy/__init__.py index 391161ed01..7a28328dfe 100644 --- a/litestar/contrib/sqlalchemy/__init__.py +++ b/litestar/contrib/sqlalchemy/__init__.py @@ -6,9 +6,9 @@ from litestar.utils import warn_deprecation __all__ = ( + "ModelT", "SQLAlchemyAsyncRepository", "SQLAlchemySyncRepository", - "ModelT", "wrap_sqlalchemy_exception", ) diff --git a/litestar/contrib/sqlalchemy/plugins/init/config/asyncio.py b/litestar/contrib/sqlalchemy/plugins/init/config/asyncio.py index e849313722..0e43db3d3f 100644 --- a/litestar/contrib/sqlalchemy/plugins/init/config/asyncio.py +++ b/litestar/contrib/sqlalchemy/plugins/init/config/asyncio.py @@ -7,11 +7,11 @@ from litestar.utils import warn_deprecation __all__ = ( - "SQLAlchemyAsyncConfig", "AlembicAsyncConfig", "AsyncSessionConfig", - "default_before_send_handler", + "SQLAlchemyAsyncConfig", "autocommit_before_send_handler", + "default_before_send_handler", ) diff --git a/litestar/contrib/sqlalchemy/plugins/init/config/common.py b/litestar/contrib/sqlalchemy/plugins/init/config/common.py index 99f4e15afa..0ccbac1ae3 100644 --- a/litestar/contrib/sqlalchemy/plugins/init/config/common.py +++ b/litestar/contrib/sqlalchemy/plugins/init/config/common.py @@ -8,9 +8,9 @@ __all__ = ( "SESSION_SCOPE_KEY", "SESSION_TERMINUS_ASGI_EVENTS", + "GenericAlembicConfig", "GenericSQLAlchemyConfig", "GenericSessionConfig", - "GenericAlembicConfig", ) diff --git a/litestar/contrib/sqlalchemy/plugins/init/config/sync.py b/litestar/contrib/sqlalchemy/plugins/init/config/sync.py index 0454bf8259..58dc6070e3 100644 --- a/litestar/contrib/sqlalchemy/plugins/init/config/sync.py +++ b/litestar/contrib/sqlalchemy/plugins/init/config/sync.py @@ -7,11 +7,11 @@ from litestar.utils import warn_deprecation __all__ = ( - "SQLAlchemySyncConfig", "AlembicSyncConfig", + "SQLAlchemySyncConfig", "SyncSessionConfig", - "default_before_send_handler", "autocommit_before_send_handler", + "default_before_send_handler", ) diff --git a/litestar/contrib/sqlalchemy/repository/__init__.py b/litestar/contrib/sqlalchemy/repository/__init__.py index 81d0aece41..07d7155440 100644 --- a/litestar/contrib/sqlalchemy/repository/__init__.py +++ b/litestar/contrib/sqlalchemy/repository/__init__.py @@ -7,9 +7,9 @@ from litestar.utils import warn_deprecation __all__ = ( + "ModelT", "SQLAlchemyAsyncRepository", "SQLAlchemySyncRepository", - "ModelT", "wrap_sqlalchemy_exception", ) diff --git a/litestar/contrib/sqlalchemy/repository/_util.py b/litestar/contrib/sqlalchemy/repository/_util.py index 2f8c438006..844272266a 100644 --- a/litestar/contrib/sqlalchemy/repository/_util.py +++ b/litestar/contrib/sqlalchemy/repository/_util.py @@ -6,8 +6,8 @@ from litestar.utils import warn_deprecation __all__ = ( - "wrap_sqlalchemy_exception", "get_instrumented_attr", + "wrap_sqlalchemy_exception", ) diff --git a/litestar/contrib/sqlalchemy/repository/types.py b/litestar/contrib/sqlalchemy/repository/types.py index f92a23cfa2..9412a28995 100644 --- a/litestar/contrib/sqlalchemy/repository/types.py +++ b/litestar/contrib/sqlalchemy/repository/types.py @@ -8,10 +8,10 @@ __all__ = ( "ModelT", - "SelectT", "RowT", - "SQLAlchemySyncRepositoryT", "SQLAlchemyAsyncRepositoryT", + "SQLAlchemySyncRepositoryT", + "SelectT", ) diff --git a/litestar/contrib/sqlalchemy/types.py b/litestar/contrib/sqlalchemy/types.py index 82646fa240..168789cac2 100644 --- a/litestar/contrib/sqlalchemy/types.py +++ b/litestar/contrib/sqlalchemy/types.py @@ -9,8 +9,8 @@ __all__ = ( "GUID", "ORA_JSONB", - "DateTimeUTC", "BigIntIdentity", + "DateTimeUTC", "JsonB", ) diff --git a/litestar/controller.py b/litestar/controller.py index 7786e023f9..a49a297c5e 100644 --- a/litestar/controller.py +++ b/litestar/controller.py @@ -73,8 +73,8 @@ class Controller: "signature_namespace", "signature_types", "tags", - "type_encoders", "type_decoders", + "type_encoders", "websocket_class", ) diff --git a/litestar/data_extractors.py b/litestar/data_extractors.py index 61993b4552..73e1a1c03c 100644 --- a/litestar/data_extractors.py +++ b/litestar/data_extractors.py @@ -12,8 +12,8 @@ "ConnectionDataExtractor", "ExtractedRequestData", "ExtractedResponseData", - "ResponseDataExtractor", "RequestExtractorField", + "ResponseDataExtractor", "ResponseExtractorField", ) @@ -66,11 +66,11 @@ class ConnectionDataExtractor: __slots__ = ( "connection_extractors", - "request_extractors", + "obfuscate_cookies", + "obfuscate_headers", "parse_body", "parse_query", - "obfuscate_headers", - "obfuscate_cookies", + "request_extractors", "skip_parse_malformed_body", ) @@ -324,7 +324,7 @@ class ExtractedResponseData(TypedDict, total=False): class ResponseDataExtractor: """Utility class to extract data from a ``Message``""" - __slots__ = ("extractors", "parse_headers", "obfuscate_headers", "obfuscate_cookies") + __slots__ = ("extractors", "obfuscate_cookies", "obfuscate_headers", "parse_headers") def __init__( self, diff --git a/litestar/datastructures/__init__.py b/litestar/datastructures/__init__.py index cddf0ae3e0..64bd7101b6 100644 --- a/litestar/datastructures/__init__.py +++ b/litestar/datastructures/__init__.py @@ -20,6 +20,7 @@ from litestar.datastructures.url import URL, Address __all__ = ( + "URL", "Accept", "Address", "CacheControlHeader", @@ -38,5 +39,4 @@ "SecretString", "State", "UploadFile", - "URL", ) diff --git a/litestar/datastructures/headers.py b/litestar/datastructures/headers.py index 17c9fc92fc..ad9e3df62f 100644 --- a/litestar/datastructures/headers.py +++ b/litestar/datastructures/headers.py @@ -385,7 +385,7 @@ def __post_init__(self) -> None: class MediaTypeHeader: """A helper class for ``Accept`` header parsing.""" - __slots__ = ("maintype", "subtype", "params", "_params_str") + __slots__ = ("_params_str", "maintype", "params", "subtype") def __init__(self, type_str: str) -> None: # preserve the original parameters, because the order might be diff --git a/litestar/datastructures/state.py b/litestar/datastructures/state.py index a11ed37791..1d5b8371b5 100644 --- a/litestar/datastructures/state.py +++ b/litestar/datastructures/state.py @@ -19,8 +19,8 @@ class ImmutableState(Mapping[str, Any]): """ __slots__ = ( - "_state", "_deep_copy", + "_state", ) _state: dict[str, Any] diff --git a/litestar/datastructures/upload_file.py b/litestar/datastructures/upload_file.py index 93d76476a2..82b1da1ade 100644 --- a/litestar/datastructures/upload_file.py +++ b/litestar/datastructures/upload_file.py @@ -12,7 +12,7 @@ class UploadFile: """Representation of a file upload""" - __slots__ = ("filename", "file", "content_type", "headers") + __slots__ = ("content_type", "file", "filename", "headers") def __init__( self, diff --git a/litestar/datastructures/url.py b/litestar/datastructures/url.py index f3441d06ef..6f78415ac8 100644 --- a/litestar/datastructures/url.py +++ b/litestar/datastructures/url.py @@ -13,7 +13,7 @@ from litestar.types import EmptyType, Scope -__all__ = ("Address", "URL") +__all__ = ("URL", "Address") _DEFAULT_SCHEME_PORTS = {"http": 80, "https": 443, "ftp": 21, "ws": 80, "wss": 443} @@ -47,8 +47,8 @@ class URL: """Representation and modification utilities of a URL.""" __slots__ = ( - "_query_params", "_parsed_url", + "_query_params", "fragment", "hostname", "netloc", diff --git a/litestar/di.py b/litestar/di.py index 066a128454..52a9adb3a1 100644 --- a/litestar/di.py +++ b/litestar/di.py @@ -26,9 +26,9 @@ class Provide: __slots__ = ( "dependency", + "has_async_generator_dependency", "has_sync_callable", "has_sync_generator_dependency", - "has_async_generator_dependency", "parsed_fn_signature", "signature_model", "sync_to_thread", diff --git a/litestar/dto/_codegen_backend.py b/litestar/dto/_codegen_backend.py index a3fb25f615..de29ba07cd 100644 --- a/litestar/dto/_codegen_backend.py +++ b/litestar/dto/_codegen_backend.py @@ -43,11 +43,11 @@ class DTOCodegenBackend(DTOBackend): __slots__ = ( - "_transfer_to_dict", - "_transfer_to_model_type", + "_encode_data", "_transfer_data_from_builtins", "_transfer_data_from_builtins_with_overrides", - "_encode_data", + "_transfer_to_dict", + "_transfer_to_model_type", ) def __init__( diff --git a/litestar/dto/_types.py b/litestar/dto/_types.py index 01f0191ddd..0ded5a85a8 100644 --- a/litestar/dto/_types.py +++ b/litestar/dto/_types.py @@ -17,7 +17,7 @@ class NestedFieldInfo: """Type for representing fields and model type of nested model type.""" - __slots__ = ("model", "field_definitions") + __slots__ = ("field_definitions", "model") model: type[Any] field_definitions: tuple[TransferDTOFieldDefinition, ...] diff --git a/litestar/events/__init__.py b/litestar/events/__init__.py index a291141af3..e3bd6e7117 100644 --- a/litestar/events/__init__.py +++ b/litestar/events/__init__.py @@ -1,4 +1,4 @@ from .emitter import BaseEventEmitterBackend, SimpleEventEmitter from .listener import EventListener, listener -__all__ = ("EventListener", "SimpleEventEmitter", "BaseEventEmitterBackend", "listener") +__all__ = ("BaseEventEmitterBackend", "EventListener", "SimpleEventEmitter", "listener") diff --git a/litestar/events/emitter.py b/litestar/events/emitter.py index 7c33c9e73f..ec6634f107 100644 --- a/litestar/events/emitter.py +++ b/litestar/events/emitter.py @@ -63,7 +63,7 @@ def emit(self, event_id: str, *args: Any, **kwargs: Any) -> None: class SimpleEventEmitter(BaseEventEmitterBackend): """Event emitter the works only in the current process""" - __slots__ = ("_queue", "_exit_stack", "_receive_stream", "_send_stream") + __slots__ = ("_exit_stack", "_queue", "_receive_stream", "_send_stream") def __init__(self, listeners: Sequence[EventListener]) -> None: """Create an event emitter instance. diff --git a/litestar/exceptions/base_exceptions.py b/litestar/exceptions/base_exceptions.py index bbd4040f5b..d23d3b5957 100644 --- a/litestar/exceptions/base_exceptions.py +++ b/litestar/exceptions/base_exceptions.py @@ -2,7 +2,7 @@ from typing import Any -__all__ = ("MissingDependencyException", "SerializationException", "LitestarException", "LitestarWarning") +__all__ = ("LitestarException", "LitestarWarning", "MissingDependencyException", "SerializationException") class LitestarException(Exception): diff --git a/litestar/exceptions/responses/__init__.py b/litestar/exceptions/responses/__init__.py index 9ed1df1c52..9db3c41f83 100644 --- a/litestar/exceptions/responses/__init__.py +++ b/litestar/exceptions/responses/__init__.py @@ -11,8 +11,8 @@ __all__ = ( "ExceptionResponseContent", - "create_exception_response", "create_debug_response", + "create_exception_response", ) diff --git a/litestar/handlers/__init__.py b/litestar/handlers/__init__.py index 822fe7e812..0abf8ee105 100644 --- a/litestar/handlers/__init__.py +++ b/litestar/handlers/__init__.py @@ -14,8 +14,8 @@ "BaseRouteHandler", "HTTPRouteHandler", "WebsocketListener", - "WebsocketRouteHandler", "WebsocketListenerRouteHandler", + "WebsocketRouteHandler", "asgi", "delete", "get", diff --git a/litestar/handlers/http_handlers/_utils.py b/litestar/handlers/http_handlers/_utils.py index ec95145ab8..d8104b1491 100644 --- a/litestar/handlers/http_handlers/_utils.py +++ b/litestar/handlers/http_handlers/_utils.py @@ -211,10 +211,8 @@ def is_empty_response_annotation(return_annotation: FieldDefinition) -> bool: Returns: Whether the return annotation is an empty response. """ - return ( - return_annotation.is_subclass_of(NoneType) - or return_annotation.is_subclass_of(Response) - and return_annotation.has_inner_subclass_of(NoneType) + return return_annotation.is_subclass_of(NoneType) or ( + return_annotation.is_subclass_of(Response) and return_annotation.has_inner_subclass_of(NoneType) ) diff --git a/litestar/handlers/http_handlers/base.py b/litestar/handlers/http_handlers/base.py index 8445d6c6ab..461c4c9bf1 100644 --- a/litestar/handlers/http_handlers/base.py +++ b/litestar/handlers/http_handlers/base.py @@ -76,13 +76,13 @@ class HTTPRouteHandler(BaseRouteHandler): __slots__ = ( "_resolved_after_response", "_resolved_before_request", - "_response_handler_mapping", "_resolved_include_in_schema", - "_resolved_response_class", "_resolved_request_class", - "_resolved_tags", - "_resolved_security", "_resolved_request_max_body_size", + "_resolved_response_class", + "_resolved_security", + "_resolved_tags", + "_response_handler_mapping", "after_request", "after_response", "background", @@ -103,6 +103,7 @@ class HTTPRouteHandler(BaseRouteHandler): "operation_id", "raises", "request_class", + "request_max_body_size", "response_class", "response_cookies", "response_description", @@ -114,7 +115,6 @@ class HTTPRouteHandler(BaseRouteHandler): "sync_to_thread", "tags", "template_name", - "request_max_body_size", ) has_sync_callable: bool diff --git a/litestar/handlers/http_handlers/decorators.py b/litestar/handlers/http_handlers/decorators.py index fe0b0cd56e..69df2c95a9 100644 --- a/litestar/handlers/http_handlers/decorators.py +++ b/litestar/handlers/http_handlers/decorators.py @@ -41,7 +41,7 @@ from litestar.types.callable_types import OperationIDCreator -__all__ = ("get", "head", "post", "put", "patch", "delete") +__all__ = ("delete", "get", "head", "patch", "post", "put") MSG_SEMANTIC_ROUTE_HANDLER_WITH_HTTP = "semantic route handlers cannot define http_method" diff --git a/litestar/handlers/websocket_handlers/listener.py b/litestar/handlers/websocket_handlers/listener.py index e4a2df7825..cfe35eb7ed 100644 --- a/litestar/handlers/websocket_handlers/listener.py +++ b/litestar/handlers/websocket_handlers/listener.py @@ -58,7 +58,7 @@ class WebsocketListenerRouteHandler(WebsocketRouteHandler): returned """ - __slots__ = { + __slots__ = { # noqa: RUF023 "connection_accept_handler": "Callback to accept a WebSocket connection. By default, calls WebSocket.accept", "on_accept": "Callback invoked after a WebSocket connection has been accepted", "on_disconnect": "Callback invoked after a WebSocket connection has been closed", diff --git a/litestar/logging/__init__.py b/litestar/logging/__init__.py index b05ceba18c..8c4ba81f56 100644 --- a/litestar/logging/__init__.py +++ b/litestar/logging/__init__.py @@ -1,3 +1,3 @@ from .config import BaseLoggingConfig, LoggingConfig, StructLoggingConfig -__all__ = ("BaseLoggingConfig", "StructLoggingConfig", "LoggingConfig") +__all__ = ("BaseLoggingConfig", "LoggingConfig", "StructLoggingConfig") diff --git a/litestar/logging/config.py b/litestar/logging/config.py index d82acac5c4..19615a229f 100644 --- a/litestar/logging/config.py +++ b/litestar/logging/config.py @@ -155,7 +155,7 @@ def _default_exception_logging_handler(logger: Logger, scope: Scope, tb: list[st class BaseLoggingConfig(ABC): """Abstract class that should be extended by logging configs.""" - __slots__ = ("log_exceptions", "traceback_line_limit", "exception_logging_handler") + __slots__ = ("exception_logging_handler", "log_exceptions", "traceback_line_limit") log_exceptions: Literal["always", "debug", "never"] """Should exceptions be logged, defaults to log exceptions when ``app.debug == True``'""" diff --git a/litestar/middleware/authentication.py b/litestar/middleware/authentication.py index f038fe5da1..bc6192c272 100644 --- a/litestar/middleware/authentication.py +++ b/litestar/middleware/authentication.py @@ -22,7 +22,7 @@ class AuthenticationResult: """Dataclass for authentication result.""" - __slots__ = ("user", "auth") + __slots__ = ("auth", "user") user: Any """The user model, this can be any value corresponding to a user of the API.""" diff --git a/litestar/middleware/base.py b/litestar/middleware/base.py index a84f73bb6b..c3c5a5f873 100644 --- a/litestar/middleware/base.py +++ b/litestar/middleware/base.py @@ -46,7 +46,7 @@ async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None: class DefineMiddleware: """Container enabling passing ``*args`` and ``**kwargs`` to Middleware class constructors and factory functions.""" - __slots__ = ("middleware", "args", "kwargs") + __slots__ = ("args", "kwargs", "middleware") def __init__(self, middleware: Callable[..., ASGIApp], *args: Any, **kwargs: Any) -> None: """Initialize ``DefineMiddleware``. diff --git a/litestar/middleware/compression/__init__.py b/litestar/middleware/compression/__init__.py index 0885932dd0..20f4939ddf 100644 --- a/litestar/middleware/compression/__init__.py +++ b/litestar/middleware/compression/__init__.py @@ -1,4 +1,4 @@ from litestar.middleware.compression.facade import CompressionFacade from litestar.middleware.compression.middleware import CompressionMiddleware -__all__ = ("CompressionMiddleware", "CompressionFacade") +__all__ = ("CompressionFacade", "CompressionMiddleware") diff --git a/litestar/middleware/compression/brotli_facade.py b/litestar/middleware/compression/brotli_facade.py index 3d01950a45..7673134436 100644 --- a/litestar/middleware/compression/brotli_facade.py +++ b/litestar/middleware/compression/brotli_facade.py @@ -19,7 +19,7 @@ class BrotliCompression(CompressionFacade): - __slots__ = ("compressor", "buffer", "compression_encoding") + __slots__ = ("buffer", "compression_encoding", "compressor") encoding = CompressionEncoding.BROTLI diff --git a/litestar/middleware/compression/gzip_facade.py b/litestar/middleware/compression/gzip_facade.py index b10ef73991..e57afbb80c 100644 --- a/litestar/middleware/compression/gzip_facade.py +++ b/litestar/middleware/compression/gzip_facade.py @@ -13,7 +13,7 @@ class GzipCompression(CompressionFacade): - __slots__ = ("compressor", "buffer", "compression_encoding") + __slots__ = ("buffer", "compression_encoding", "compressor") encoding = CompressionEncoding.GZIP diff --git a/litestar/openapi/__init__.py b/litestar/openapi/__init__.py index 8cc83d3697..50019b7863 100644 --- a/litestar/openapi/__init__.py +++ b/litestar/openapi/__init__.py @@ -2,4 +2,4 @@ from .controller import OpenAPIController from .datastructures import ResponseSpec -__all__ = ("OpenAPIController", "OpenAPIConfig", "ResponseSpec") +__all__ = ("OpenAPIConfig", "OpenAPIController", "ResponseSpec") diff --git a/litestar/openapi/spec/__init__.py b/litestar/openapi/spec/__init__.py index 438c3514ba..1d7c9ed9a5 100644 --- a/litestar/openapi/spec/__init__.py +++ b/litestar/openapi/spec/__init__.py @@ -32,6 +32,7 @@ from .xml import XML __all__ = ( + "XML", "BaseSchemaObject", "Callback", "Components", @@ -64,5 +65,4 @@ "Server", "ServerVariable", "Tag", - "XML", ) diff --git a/litestar/pagination.py b/litestar/pagination.py index 6e81371958..9bfe5ee5ca 100644 --- a/litestar/pagination.py +++ b/litestar/pagination.py @@ -27,7 +27,7 @@ class ClassicPagination(Generic[T]): """Container for data returned using limit/offset pagination.""" - __slots__ = ("items", "page_size", "current_page", "total_pages") + __slots__ = ("current_page", "items", "page_size", "total_pages") items: List[T] """List of data being sent as part of the response.""" @@ -70,7 +70,7 @@ class OffsetPagination(Generic[T]): # type: ignore[no-redef] class CursorPagination(Generic[C, T]): """Container for data returned using cursor pagination.""" - __slots__ = ("items", "results_per_page", "cursor", "next_cursor") + __slots__ = ("cursor", "items", "next_cursor", "results_per_page") items: List[T] """List of data being sent as part of the response.""" diff --git a/litestar/plugins/__init__.py b/litestar/plugins/__init__.py index f09310436d..39421e7d30 100644 --- a/litestar/plugins/__init__.py +++ b/litestar/plugins/__init__.py @@ -11,13 +11,13 @@ ) __all__ = ( - "SerializationPluginProtocol", - "DIPlugin", "CLIPlugin", + "CLIPluginProtocol", + "DIPlugin", "InitPluginProtocol", - "OpenAPISchemaPluginProtocol", "OpenAPISchemaPlugin", + "OpenAPISchemaPluginProtocol", "PluginProtocol", - "CLIPluginProtocol", "PluginRegistry", + "SerializationPluginProtocol", ) diff --git a/litestar/plugins/base.py b/litestar/plugins/base.py index 41b0c34bb5..c043fbd7cf 100644 --- a/litestar/plugins/base.py +++ b/litestar/plugins/base.py @@ -18,15 +18,15 @@ from litestar.typing import FieldDefinition __all__ = ( - "SerializationPluginProtocol", + "CLIPlugin", + "CLIPluginProtocol", + "DIPlugin", "InitPluginProtocol", - "OpenAPISchemaPluginProtocol", "OpenAPISchemaPlugin", + "OpenAPISchemaPluginProtocol", "PluginProtocol", - "CLIPlugin", - "CLIPluginProtocol", "PluginRegistry", - "DIPlugin", + "SerializationPluginProtocol", ) @@ -271,7 +271,7 @@ def is_constrained_field(field_definition: FieldDefinition) -> bool: class PluginRegistry: - __slots__ = { + __slots__ = { # noqa: RUF023 "init": "Plugins that implement the InitPluginProtocol", "openapi": "Plugins that implement the OpenAPISchemaPluginProtocol", "receive_route": "ReceiveRoutePlugin instances", diff --git a/litestar/plugins/htmx.py b/litestar/plugins/htmx.py index c1d47d66bd..347465ba18 100644 --- a/litestar/plugins/htmx.py +++ b/litestar/plugins/htmx.py @@ -28,26 +28,26 @@ ) __all__ = ( - "HTMXPlugin", + "ClientRedirect", + "ClientRefresh", + "EventAfterType", "HTMXConfig", "HTMXDetails", "HTMXHeaders", + "HTMXPlugin", "HTMXRequest", - "HXStopPolling", + "HTMXTemplate", "HXLocation", - "ClientRedirect", - "ClientRefresh", + "HXStopPolling", + "HtmxHeaderType", + "LocationType", "PushUrl", + "PushUrlType", + "ReSwapMethod", "ReplaceUrl", "Reswap", "Retarget", "TriggerEvent", - "HTMXTemplate", - "HtmxHeaderType", - "LocationType", "TriggerEventType", - "EventAfterType", - "PushUrlType", - "ReSwapMethod", "_utils", ) diff --git a/litestar/plugins/prometheus/__init__.py b/litestar/plugins/prometheus/__init__.py index 1ccb494695..b5d8076169 100644 --- a/litestar/plugins/prometheus/__init__.py +++ b/litestar/plugins/prometheus/__init__.py @@ -2,4 +2,4 @@ from .controller import PrometheusController from .middleware import PrometheusMiddleware -__all__ = ("PrometheusMiddleware", "PrometheusConfig", "PrometheusController") +__all__ = ("PrometheusConfig", "PrometheusController", "PrometheusMiddleware") diff --git a/litestar/plugins/pydantic/__init__.py b/litestar/plugins/pydantic/__init__.py index 8504efad9f..6b275edf3a 100644 --- a/litestar/plugins/pydantic/__init__.py +++ b/litestar/plugins/pydantic/__init__.py @@ -16,11 +16,11 @@ from litestar.types.serialization import PydanticV1FieldsListType, PydanticV2FieldsListType __all__ = ( + "PydanticDIPlugin", "PydanticDTO", "PydanticInitPlugin", - "PydanticSchemaPlugin", "PydanticPlugin", - "PydanticDIPlugin", + "PydanticSchemaPlugin", ) diff --git a/litestar/plugins/sqlalchemy.py b/litestar/plugins/sqlalchemy.py index f00f430df6..df893225a5 100644 --- a/litestar/plugins/sqlalchemy.py +++ b/litestar/plugins/sqlalchemy.py @@ -7,46 +7,46 @@ from litestar.utils import warn_deprecation __all__ = ( - "filters", - "utils", - "operations", - "base", - "types", - "repository", - "service", - "mixins", - "exceptions", - "async_autocommit_handler_maker", - "sync_autocommit_handler_maker", - "async_default_handler_maker", - "sync_default_handler_maker", - "sync_autocommit_before_send_handler", - "async_autocommit_before_send_handler", - "sync_default_before_send_handler", - "async_default_before_send_handler", - "AlembicCommands", "AlembicAsyncConfig", + "AlembicCommands", "AlembicSyncConfig", "AsyncSessionConfig", - "SyncSessionConfig", - "SQLAlchemyDTO", - "SQLAlchemyDTOConfig", - "SQLAlchemyAsyncConfig", - "SQLAlchemyInitPlugin", - "SQLAlchemyPlugin", - "SQLAlchemySerializationPlugin", - "SQLAlchemySyncConfig", - "EngineConfig", # deprecated "AuditColumns", "BigIntAuditBase", "BigIntBase", "BigIntPrimaryKey", "CommonTableAttributes", + "EngineConfig", + "SQLAlchemyAsyncConfig", + "SQLAlchemyDTO", + "SQLAlchemyDTOConfig", + "SQLAlchemyInitPlugin", + "SQLAlchemyPlugin", + "SQLAlchemySerializationPlugin", + "SQLAlchemySyncConfig", + "SyncSessionConfig", "UUIDAuditBase", "UUIDBase", "UUIDPrimaryKey", + "async_autocommit_before_send_handler", + "async_autocommit_handler_maker", + "async_default_before_send_handler", + "async_default_handler_maker", + "base", + "exceptions", + "filters", + "mixins", + "operations", "orm_registry", + "repository", + "service", + "sync_autocommit_before_send_handler", + "sync_autocommit_handler_maker", + "sync_default_before_send_handler", + "sync_default_handler_maker", + "types", + "utils", ) diff --git a/litestar/repository/_filters.py b/litestar/repository/_filters.py index f6b787e95f..cb045bf1e5 100644 --- a/litestar/repository/_filters.py +++ b/litestar/repository/_filters.py @@ -2,9 +2,9 @@ from __future__ import annotations -from collections import abc # noqa: TCH003 +from collections import abc # noqa: TC003 from dataclasses import dataclass -from datetime import datetime # noqa: TCH003 +from datetime import datetime # noqa: TC003 from typing import TYPE_CHECKING, Any, Generic, Literal, TypeVar if TYPE_CHECKING: @@ -17,11 +17,11 @@ "CollectionFilter", "FilterTypes", "LimitOffset", - "OrderBy", - "SearchFilter", "NotInCollectionFilter", - "OnBeforeAfter", "NotInSearchFilter", + "OnBeforeAfter", + "OrderBy", + "SearchFilter", ) diff --git a/litestar/repository/filters.py b/litestar/repository/filters.py index e0cce48ab3..de30db16a3 100644 --- a/litestar/repository/filters.py +++ b/litestar/repository/filters.py @@ -29,9 +29,9 @@ "CollectionFilter", "FilterTypes", "LimitOffset", - "OrderBy", - "SearchFilter", "NotInCollectionFilter", - "OnBeforeAfter", "NotInSearchFilter", + "OnBeforeAfter", + "OrderBy", + "SearchFilter", ) diff --git a/litestar/repository/handlers.py b/litestar/repository/handlers.py index 0bc1434a55..5ddf639567 100644 --- a/litestar/repository/handlers.py +++ b/litestar/repository/handlers.py @@ -15,7 +15,7 @@ if TYPE_CHECKING: from litestar.config.app import AppConfig -__all__ = ("signature_namespace_values", "on_app_init") +__all__ = ("on_app_init", "signature_namespace_values") signature_namespace_values = { "BeforeAfter": BeforeAfter, diff --git a/litestar/response/base.py b/litestar/response/base.py index 67eec09159..92c7c1de6b 100644 --- a/litestar/response/base.py +++ b/litestar/response/base.py @@ -43,14 +43,14 @@ class ASGIResponse: """A low-level ASGI response class.""" __slots__ = ( + "_encoded_cookies", "background", "body", "content_length", "encoding", + "headers", "is_head_response", "status_code", - "_encoded_cookies", - "headers", ) _should_set_content_length: ClassVar[bool] = True @@ -212,8 +212,8 @@ class Response(Generic[T]): "encoding", "headers", "media_type", - "status_code", "response_type_encoders", + "status_code", ) content: T diff --git a/litestar/response/file.py b/litestar/response/file.py index 1fc6f8632d..2cc60ec126 100644 --- a/litestar/response/file.py +++ b/litestar/response/file.py @@ -237,10 +237,10 @@ class File(Response): "chunk_size", "content_disposition_type", "etag", + "file_info", "file_path", "file_system", "filename", - "file_info", "stat_result", ) diff --git a/litestar/response/sse.py b/litestar/response/sse.py index 48a9192b98..ca9bf991cb 100644 --- a/litestar/response/sse.py +++ b/litestar/response/sse.py @@ -19,7 +19,7 @@ class _ServerSentEventIterator(AsyncIteratorWrapper[bytes]): - __slots__ = ("content_async_iterator", "event_id", "event_type", "retry_duration", "comment_message") + __slots__ = ("comment_message", "content_async_iterator", "event_id", "event_type", "retry_duration") content_async_iterator: AsyncIterable[SSEData] diff --git a/litestar/response/template.py b/litestar/response/template.py index 6499aaec01..06743a084f 100644 --- a/litestar/response/template.py +++ b/litestar/response/template.py @@ -27,9 +27,9 @@ class Template(Response[bytes]): """Template-based response, rendering a given template into a bytes string.""" __slots__ = ( + "context", "template_name", "template_str", - "context", ) def __init__( diff --git a/litestar/routes/__init__.py b/litestar/routes/__init__.py index c8b5d3d23d..c7404f4957 100644 --- a/litestar/routes/__init__.py +++ b/litestar/routes/__init__.py @@ -3,4 +3,4 @@ from .http import HTTPRoute from .websocket import WebSocketRoute -__all__ = ("BaseRoute", "ASGIRoute", "WebSocketRoute", "HTTPRoute") +__all__ = ("ASGIRoute", "BaseRoute", "HTTPRoute", "WebSocketRoute") diff --git a/litestar/routes/base.py b/litestar/routes/base.py index 6130c41c0e..40ecd706c6 100644 --- a/litestar/routes/base.py +++ b/litestar/routes/base.py @@ -77,9 +77,9 @@ class BaseRoute(ABC): "handler_names", "methods", "path", + "path_components", "path_format", "path_parameters", - "path_components", "scope_type", ) diff --git a/litestar/routes/websocket.py b/litestar/routes/websocket.py index 6346e2e0e5..67019b10b8 100644 --- a/litestar/routes/websocket.py +++ b/litestar/routes/websocket.py @@ -18,8 +18,8 @@ class WebSocketRoute(BaseRoute): """A websocket route, handling a single ``WebsocketRouteHandler``""" __slots__ = ( - "route_handler", "handler_parameter_model", + "route_handler", ) def __init__( diff --git a/litestar/security/jwt/middleware.py b/litestar/security/jwt/middleware.py index 6426a2158f..305f4011a3 100644 --- a/litestar/security/jwt/middleware.py +++ b/litestar/security/jwt/middleware.py @@ -28,15 +28,15 @@ class JWTAuthenticationMiddleware(AbstractAuthenticationMiddleware): __slots__ = ( "algorithm", "auth_header", + "require_claims", "retrieve_user_handler", - "token_secret", - "token_cls", + "strict_audience", "token_audience", + "token_cls", "token_issuer", - "require_claims", + "token_secret", "verify_expiry", "verify_not_before", - "strict_audience", ) def __init__( diff --git a/litestar/security/jwt/token.py b/litestar/security/jwt/token.py index a7df89d8c4..05421657dc 100644 --- a/litestar/security/jwt/token.py +++ b/litestar/security/jwt/token.py @@ -14,8 +14,8 @@ from typing_extensions import Self __all__ = ( - "Token", "JWTDecodeOptions", + "Token", ) diff --git a/litestar/serialization/__init__.py b/litestar/serialization/__init__.py index 0a9189eeac..54752136cb 100644 --- a/litestar/serialization/__init__.py +++ b/litestar/serialization/__init__.py @@ -9,9 +9,9 @@ ) __all__ = ( - "default_deserializer", "decode_json", "decode_msgpack", + "default_deserializer", "default_serializer", "encode_json", "encode_msgpack", diff --git a/litestar/static_files/base.py b/litestar/static_files/base.py index 7afad1fa06..896b2ebbbc 100644 --- a/litestar/static_files/base.py +++ b/litestar/static_files/base.py @@ -22,7 +22,7 @@ class StaticFiles: """ASGI App that handles file sending.""" - __slots__ = ("is_html_mode", "directories", "adapter", "send_as_attachment", "headers") + __slots__ = ("adapter", "directories", "headers", "is_html_mode", "send_as_attachment") def __init__( self, diff --git a/litestar/static_files/config.py b/litestar/static_files/config.py index 8ee77b77de..7bd0c71728 100644 --- a/litestar/static_files/config.py +++ b/litestar/static_files/config.py @@ -1,13 +1,13 @@ from __future__ import annotations from dataclasses import dataclass -from pathlib import PurePath # noqa: TCH003 +from pathlib import PurePath # noqa: TC003 from typing import TYPE_CHECKING, Any, Sequence from litestar.exceptions import ImproperlyConfiguredException from litestar.file_system import BaseLocalFileSystem from litestar.handlers import asgi, get, head -from litestar.response.file import ASGIFileResponse # noqa: TCH001 +from litestar.response.file import ASGIFileResponse # noqa: TC001 from litestar.router import Router from litestar.static_files.base import StaticFiles from litestar.utils import normalize_path, warn_deprecation diff --git a/litestar/stores/base.py b/litestar/stores/base.py index 69a63663e5..d0aa1fba52 100644 --- a/litestar/stores/base.py +++ b/litestar/stores/base.py @@ -14,7 +14,7 @@ from typing_extensions import Self -__all__ = ("Store", "NamespacedStore", "StorageObject") +__all__ = ("NamespacedStore", "StorageObject", "Store") class Store(ABC): diff --git a/litestar/stores/file.py b/litestar/stores/file.py index 0320e47464..979d256ded 100644 --- a/litestar/stores/file.py +++ b/litestar/stores/file.py @@ -28,7 +28,7 @@ def _safe_file_name(name: str) -> str: class FileStore(NamespacedStore): """File based, thread and process safe, asynchronous key/value store.""" - __slots__ = {"path": "file path", "create_directories": "flag to create directories in path"} + __slots__ = {"create_directories": "flag to create directories in path", "path": "file path"} def __init__(self, path: PathLike[str], *, create_directories: bool = False) -> None: """Initialize ``FileStorage``. diff --git a/litestar/stores/memory.py b/litestar/stores/memory.py index 1da89317aa..07c131b4be 100644 --- a/litestar/stores/memory.py +++ b/litestar/stores/memory.py @@ -17,7 +17,7 @@ class MemoryStore(Store): """In memory, atomic, asynchronous key/value store.""" - __slots__ = ("_store", "_lock") + __slots__ = ("_lock", "_store") def __init__(self) -> None: """Initialize :class:`MemoryStore`""" diff --git a/litestar/stores/registry.py b/litestar/stores/registry.py index 11a08c2008..2cfb930acd 100644 --- a/litestar/stores/registry.py +++ b/litestar/stores/registry.py @@ -18,7 +18,7 @@ def default_default_factory(name: str) -> Store: class StoreRegistry: """Registry for :class:`Store <.base.Store>` instances.""" - __slots__ = ("_stores", "_default_factory") + __slots__ = ("_default_factory", "_stores") def __init__( self, stores: dict[str, Store] | None = None, default_factory: Callable[[str], Store] = default_default_factory diff --git a/litestar/template/__init__.py b/litestar/template/__init__.py index 5989cea229..0f0812e4e4 100644 --- a/litestar/template/__init__.py +++ b/litestar/template/__init__.py @@ -1,4 +1,4 @@ from litestar.template.base import TemplateEngineProtocol, TemplateProtocol from litestar.template.config import TemplateConfig -__all__ = ("TemplateEngineProtocol", "TemplateProtocol", "TemplateConfig") +__all__ = ("TemplateConfig", "TemplateEngineProtocol", "TemplateProtocol") diff --git a/litestar/testing/__init__.py b/litestar/testing/__init__.py index 55af446ac5..d09fb90aa7 100644 --- a/litestar/testing/__init__.py +++ b/litestar/testing/__init__.py @@ -8,9 +8,9 @@ __all__ = ( "AsyncTestClient", "BaseTestClient", - "create_async_test_client", - "create_test_client", "RequestFactory", "TestClient", "WebSocketTestSession", + "create_async_test_client", + "create_test_client", ) diff --git a/litestar/testing/client/__init__.py b/litestar/testing/client/__init__.py index 5d03a7a9e7..b22b04e0a3 100644 --- a/litestar/testing/client/__init__.py +++ b/litestar/testing/client/__init__.py @@ -33,4 +33,4 @@ from .base import BaseTestClient from .sync_client import TestClient -__all__ = ("TestClient", "AsyncTestClient", "BaseTestClient") +__all__ = ("AsyncTestClient", "BaseTestClient", "TestClient") diff --git a/litestar/testing/client/base.py b/litestar/testing/client/base.py index 9820729351..eeec983b79 100644 --- a/litestar/testing/client/base.py +++ b/litestar/testing/client/base.py @@ -97,13 +97,13 @@ class BaseTestClient(Generic[T]): blocking_portal: BlockingPortal __slots__ = ( + "_session_backend", "app", - "base_url", "backend", "backend_options", - "session_config", - "_session_backend", + "base_url", "cookies", + "session_config", ) def __init__( diff --git a/litestar/testing/life_span_handler.py b/litestar/testing/life_span_handler.py index 8c2ee5f2dd..7141f4eeb5 100644 --- a/litestar/testing/life_span_handler.py +++ b/litestar/testing/life_span_handler.py @@ -24,11 +24,11 @@ class LifeSpanHandler(Generic[T]): __slots__ = ( - "stream_send", - "stream_receive", + "_startup_done", "client", + "stream_receive", + "stream_send", "task", - "_startup_done", ) def __init__(self, client: T) -> None: diff --git a/litestar/testing/request_factory.py b/litestar/testing/request_factory.py index 6166e6f1ab..e25b6b0956 100644 --- a/litestar/testing/request_factory.py +++ b/litestar/testing/request_factory.py @@ -55,12 +55,12 @@ class RequestFactory: __slots__ = ( "app", - "server", + "handler_kwargs", "port", "root_path", "scheme", - "handler_kwargs", "serializer", + "server", ) def __init__( diff --git a/litestar/types/__init__.py b/litestar/types/__init__.py index 90e319277c..ef91444b88 100644 --- a/litestar/types/__init__.py +++ b/litestar/types/__init__.py @@ -142,13 +142,13 @@ "ResponseHeaders", "RouteHandlerMapItem", "RouteHandlerType", + "SSEData", "Scope", "ScopeSession", "Scopes", "Send", "Serializer", "StreamType", - "SSEData", "SyncOrAsyncUnion", "TypeDecodersSequence", "TypeEncodersMap", diff --git a/litestar/types/asgi_types.py b/litestar/types/asgi_types.py index 09a2575c60..abbcf2ae77 100644 --- a/litestar/types/asgi_types.py +++ b/litestar/types/asgi_types.py @@ -51,7 +51,6 @@ "ASGIApp", "ASGIVersion", "BaseScope", - "HeaderScope", "HTTPDisconnectEvent", "HTTPReceiveMessage", "HTTPRequestEvent", @@ -60,6 +59,7 @@ "HTTPScope", "HTTPSendMessage", "HTTPServerPushEvent", + "HeaderScope", "LifeSpanReceive", "LifeSpanReceiveMessage", "LifeSpanScope", diff --git a/litestar/types/builtin_types.py b/litestar/types/builtin_types.py index 335dedd798..151442dc7b 100644 --- a/litestar/types/builtin_types.py +++ b/litestar/types/builtin_types.py @@ -9,9 +9,9 @@ __all__ = ( "NoneType", + "TypedDictClass", "UnionType", "UnionTypes", - "TypedDictClass", ) NoneType: type[None] = type(None) diff --git a/litestar/types/helper_types.py b/litestar/types/helper_types.py index 588ae5409f..492ed089e8 100644 --- a/litestar/types/helper_types.py +++ b/litestar/types/helper_types.py @@ -25,7 +25,7 @@ T = TypeVar("T") -__all__ = ("OptionalSequence", "SyncOrAsyncUnion", "AnyIOBackend", "StreamType", "MaybePartial", "SSEData") +__all__ = ("AnyIOBackend", "MaybePartial", "OptionalSequence", "SSEData", "StreamType", "SyncOrAsyncUnion") OptionalSequence: TypeAlias = Optional[Sequence[T]] """Types 'T' as union of Sequence[T] and None.""" diff --git a/litestar/types/serialization.py b/litestar/types/serialization.py index 15ec4308ec..098d52ec5c 100644 --- a/litestar/types/serialization.py +++ b/litestar/types/serialization.py @@ -42,13 +42,13 @@ AttrsInstance = Any # type: ignore[assignment, misc] __all__ = ( - "LitestarEncodableType", - "EncodableBuiltinType", + "DataContainerType", "EncodableBuiltinCollectionType", - "EncodableStdLibType", - "EncodableStdLibIPType", + "EncodableBuiltinType", "EncodableMsgSpecType", - "DataContainerType", + "EncodableStdLibIPType", + "EncodableStdLibType", + "LitestarEncodableType", ) EncodableBuiltinType: TypeAlias = "None | bool | int | float | str | bytes | bytearray" diff --git a/litestar/utils/__init__.py b/litestar/utils/__init__.py index c15988e067..af86b83850 100644 --- a/litestar/utils/__init__.py +++ b/litestar/utils/__init__.py @@ -32,9 +32,9 @@ from .typing import get_origin_or_inner_type, make_non_optional_union __all__ = ( - "ensure_async_callable", "AsyncIteratorWrapper", "deprecated", + "ensure_async_callable", "find_index", "get_enum_string_value", "get_name", diff --git a/litestar/utils/helpers.py b/litestar/utils/helpers.py index c25fe35f25..c8202e9c2d 100644 --- a/litestar/utils/helpers.py +++ b/litestar/utils/helpers.py @@ -15,9 +15,9 @@ __all__ = ( "get_enum_string_value", "get_name", + "unique_name_for_scope", "unwrap_partial", "url_quote", - "unique_name_for_scope", ) T = TypeVar("T") diff --git a/litestar/utils/scope/state.py b/litestar/utils/scope/state.py index cc9fd31d5d..5ef6c3f36d 100644 --- a/litestar/utils/scope/state.py +++ b/litestar/utils/scope/state.py @@ -26,6 +26,7 @@ class ScopeState: """ __slots__ = ( + "_compat_ns", "accept", "base_url", "body", @@ -47,7 +48,6 @@ class ScopeState: "response_started", "session_id", "url", - "_compat_ns", ) def __init__(self) -> None: diff --git a/litestar/utils/signature.py b/litestar/utils/signature.py index 08019328e3..becd1bfea7 100644 --- a/litestar/utils/signature.py +++ b/litestar/utils/signature.py @@ -29,10 +29,10 @@ def _get_defaults(_: Any) -> Any: ... __all__ = ( + "ParsedSignature", "add_types_to_signature_namespace", - "merge_signature_namespaces", "get_fn_type_hints", - "ParsedSignature", + "merge_signature_namespaces", ) _GLOBAL_NAMES = { @@ -184,7 +184,7 @@ class ParsedSignature: The only post-processing that occurs is the conversion of any forward referenced type annotations. """ - __slots__ = ("parameters", "return_type", "original_signature") + __slots__ = ("original_signature", "parameters", "return_type") parameters: dict[str, FieldDefinition] """A mapping of parameter names to ParsedSignatureParameter instances.""" diff --git a/litestar/utils/sync.py b/litestar/utils/sync.py index 7fc21b0182..7c91845a07 100644 --- a/litestar/utils/sync.py +++ b/litestar/utils/sync.py @@ -15,7 +15,7 @@ from litestar.concurrency import sync_to_thread from litestar.utils.predicates import is_async_callable -__all__ = ("ensure_async_callable", "AsyncIteratorWrapper", "AsyncCallable", "is_async_callable") +__all__ = ("AsyncCallable", "AsyncIteratorWrapper", "ensure_async_callable", "is_async_callable") P = ParamSpec("P") @@ -48,7 +48,7 @@ def __call__(self, *args: P.args, **kwargs: P.kwargs) -> Awaitable[T]: # pyrigh class AsyncIteratorWrapper(Generic[T]): """Asynchronous generator, wrapping an iterable or iterator.""" - __slots__ = ("iterator", "generator") + __slots__ = ("generator", "iterator") def __init__(self, iterator: Iterator[T] | Iterable[T]) -> None: """Take a sync iterator or iterable and yields values from it asynchronously.