From bf887ebbfe58fecbb979f9a4799ac0002dc72e82 Mon Sep 17 00:00:00 2001 From: Federico Caselli Date: Sun, 11 Aug 2024 12:31:50 +0200 Subject: [PATCH] style: run ruff --- falcon/app.py | 1 + falcon/app_helpers.py | 1 + falcon/asgi_spec.py | 1 + falcon/errors.py | 6 ++---- falcon/forwarded.py | 3 +-- falcon/hooks.py | 1 + falcon/http_error.py | 7 ++----- falcon/http_status.py | 4 ++-- falcon/inspect.py | 23 +++++++++++++---------- falcon/media/handlers.py | 3 ++- falcon/middleware.py | 5 +---- falcon/redirects.py | 4 ++-- falcon/request.py | 1 + falcon/response.py | 4 ++-- falcon/typing.py | 33 +++++++++++++++++---------------- 15 files changed, 49 insertions(+), 48 deletions(-) diff --git a/falcon/app.py b/falcon/app.py index a170cde77..53cffe397 100644 --- a/falcon/app.py +++ b/falcon/app.py @@ -13,6 +13,7 @@ # limitations under the License. """Falcon App class.""" + from functools import wraps from inspect import iscoroutinefunction import pathlib diff --git a/falcon/app_helpers.py b/falcon/app_helpers.py index 7ea8b3002..db6d7cc24 100644 --- a/falcon/app_helpers.py +++ b/falcon/app_helpers.py @@ -13,6 +13,7 @@ # limitations under the License. """Utilities for the App class.""" + from __future__ import annotations from inspect import iscoroutinefunction diff --git a/falcon/asgi_spec.py b/falcon/asgi_spec.py index 02f214dec..bca282b37 100644 --- a/falcon/asgi_spec.py +++ b/falcon/asgi_spec.py @@ -13,6 +13,7 @@ # limitations under the License. """Constants, etc. defined by the ASGI specification.""" + from __future__ import annotations diff --git a/falcon/errors.py b/falcon/errors.py index 13d0aaa70..5175308eb 100644 --- a/falcon/errors.py +++ b/falcon/errors.py @@ -33,13 +33,11 @@ def on_get(self, req, resp): # -- snip -- """ + from __future__ import annotations from datetime import datetime -from typing import Iterable -from typing import Optional -from typing import TYPE_CHECKING -from typing import Union +from typing import Iterable, Optional, TYPE_CHECKING, Union from falcon.http_error import HTTPError import falcon.status_codes as status diff --git a/falcon/forwarded.py b/falcon/forwarded.py index eee783b40..f855b3661 100644 --- a/falcon/forwarded.py +++ b/falcon/forwarded.py @@ -20,8 +20,7 @@ import re import string -from typing import List -from typing import Optional +from typing import List, Optional from falcon.util.uri import unquote_string diff --git a/falcon/hooks.py b/falcon/hooks.py index 45c477d24..5ca50aefb 100644 --- a/falcon/hooks.py +++ b/falcon/hooks.py @@ -13,6 +13,7 @@ # limitations under the License. """Hook decorators.""" + from __future__ import annotations from functools import wraps diff --git a/falcon/http_error.py b/falcon/http_error.py index 16a1c8ef4..f684de63f 100644 --- a/falcon/http_error.py +++ b/falcon/http_error.py @@ -12,14 +12,11 @@ # See the License for the specific language governing permissions and # limitations under the License. """HTTPError exception class.""" + from __future__ import annotations from collections import OrderedDict -from typing import MutableMapping -from typing import Optional -from typing import Type -from typing import TYPE_CHECKING -from typing import Union +from typing import MutableMapping, Optional, Type, TYPE_CHECKING, Union import xml.etree.ElementTree as et from falcon.constants import MEDIA_JSON diff --git a/falcon/http_status.py b/falcon/http_status.py index 54e1ebac0..927b89bb4 100644 --- a/falcon/http_status.py +++ b/falcon/http_status.py @@ -12,10 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. """HTTPStatus exception class.""" + from __future__ import annotations -from typing import Optional -from typing import TYPE_CHECKING +from typing import Optional, TYPE_CHECKING from falcon.util import http_status_to_code from falcon.util.deprecation import AttributeRemovedError diff --git a/falcon/inspect.py b/falcon/inspect.py index f1edb8650..9aac44cb0 100644 --- a/falcon/inspect.py +++ b/falcon/inspect.py @@ -13,20 +13,23 @@ # limitations under the License. """Inspect utilities for falcon applications.""" + from __future__ import annotations from functools import partial import inspect -from typing import Any -from typing import Callable -from typing import cast -from typing import Dict -from typing import Iterable -from typing import List -from typing import Optional -from typing import Tuple -from typing import Type -from typing import Union +from typing import ( + Any, + Callable, + cast, + Dict, + Iterable, + List, + Optional, + Tuple, + Type, + Union, +) from falcon import app_helpers from falcon.app import App diff --git a/falcon/media/handlers.py b/falcon/media/handlers.py index 4e96e6b32..36f38e128 100644 --- a/falcon/media/handlers.py +++ b/falcon/media/handlers.py @@ -16,8 +16,9 @@ from falcon.util import misc from falcon.vendor import mimeparse -if typing.TYPE_CHECKING: # pragma: no cover +if typing.TYPE_CHECKING: # pragma: no cover from typing import Mapping + from falcon.typing import Serializer diff --git a/falcon/middleware.py b/falcon/middleware.py index a89a2325a..5772e16c7 100644 --- a/falcon/middleware.py +++ b/falcon/middleware.py @@ -1,9 +1,6 @@ from __future__ import annotations -from typing import Any -from typing import Iterable -from typing import Optional -from typing import Union +from typing import Any, Iterable, Optional, Union from .request import Request from .response import Response diff --git a/falcon/redirects.py b/falcon/redirects.py index 3f2e94760..e1001bbab 100644 --- a/falcon/redirects.py +++ b/falcon/redirects.py @@ -12,10 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. """HTTPStatus specializations for 3xx redirects.""" + from __future__ import annotations -from typing import Optional -from typing import TYPE_CHECKING +from typing import Optional, TYPE_CHECKING import falcon from falcon.http_status import HTTPStatus diff --git a/falcon/request.py b/falcon/request.py index f20b2c3d5..6aa9a5982 100644 --- a/falcon/request.py +++ b/falcon/request.py @@ -11,6 +11,7 @@ # limitations under the License. """Request class.""" + from __future__ import annotations from collections import UserDict diff --git a/falcon/response.py b/falcon/response.py index 9b72e4b2b..5d29c1c0c 100644 --- a/falcon/response.py +++ b/falcon/response.py @@ -13,12 +13,12 @@ # limitations under the License. """Response class.""" + from __future__ import annotations import functools import mimetypes -from typing import Optional -from typing import TYPE_CHECKING +from typing import Optional, TYPE_CHECKING from falcon.constants import _DEFAULT_STATIC_MEDIA_TYPES from falcon.constants import _UNSET diff --git a/falcon/typing.py b/falcon/typing.py index b539676df..9733e528f 100644 --- a/falcon/typing.py +++ b/falcon/typing.py @@ -12,39 +12,40 @@ # See the License for the specific language governing permissions and # limitations under the License. """Shorthand definitions for more complex types.""" + from __future__ import annotations import http -from typing import Any -from typing import Callable -from typing import Dict -from typing import List -from typing import MutableMapping -from typing import Optional -from typing import Pattern -from typing import Tuple -from typing import TYPE_CHECKING -from typing import Union +from typing import ( + Any, + Callable, + Dict, + List, + MutableMapping, + Optional, + Pattern, + Tuple, + TYPE_CHECKING, + Union, +) if TYPE_CHECKING: + from typing import Protocol + from falcon.request import Request from falcon.response import Response - from typing import Protocol - class Serializer(Protocol): def serialize( self, media: MutableMapping[str, Union[str, int, None, Link]], content_type: str, - ) -> bytes: - ... + ) -> bytes: ... class MediaHandlers(Protocol): def _resolve( self, media_type: str, default: str, raise_not_found: bool = False - ) -> Tuple[Serializer, Optional[Callable], Optional[Callable]]: - ... + ) -> Tuple[Serializer, Optional[Callable], Optional[Callable]]: ... Link = Dict[str, str]