Skip to content

Commit

Permalink
keylime/web/base/controller: Move TypeAlias definition out of class
Browse files Browse the repository at this point in the history
This is to fix a typing issue reported by pyright

Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
  • Loading branch information
ansasaki committed Sep 23, 2024
1 parent 943b295 commit f65bf6e
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions keylime/web/base/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@
from keylime.models.base.basic_model import BasicModel
from keylime.web.base.action_handler import ActionHandler

PathParams: TypeAlias = Mapping[str, str]
QueryParams: TypeAlias = Mapping[str, str | Sequence[str]]
MultipartParams: TypeAlias = Mapping[str, Union[str, bytes, Sequence[str | bytes]]]
FormParams: TypeAlias = Union[QueryParams, MultipartParams]
JSONConvertible: TypeAlias = Union[str, int, float, bool, None, "JSONObjectConvertible", "JSONArrayConvertible"]
JSONObjectConvertible: TypeAlias = Mapping[str, JSONConvertible]
JSONArrayConvertible: TypeAlias = Sequence[JSONConvertible] # pyright: ignore[reportInvalidTypeForm]
Params: TypeAlias = Mapping[str, Union[str, bytes, Sequence[str | bytes], JSONObjectConvertible, JSONArrayConvertible]]


class Controller:
"""A controller represents a collection of actions that an API consumer can perform on a resource or set of
Expand Down Expand Up @@ -64,17 +73,6 @@ async def show(self, id, format=None, **params):
typically defined by each individual model).
"""

PathParams: TypeAlias = Mapping[str, str]
QueryParams: TypeAlias = Mapping[str, str | Sequence[str]]
MultipartParams: TypeAlias = Mapping[str, Union[str, bytes, Sequence[str | bytes]]]
FormParams: TypeAlias = Union[QueryParams, MultipartParams]
JSONConvertible: TypeAlias = Union[str, int, float, bool, None, "JSONObjectConvertible", "JSONArrayConvertible"]
JSONObjectConvertible: TypeAlias = Mapping[str, JSONConvertible]
JSONArrayConvertible: TypeAlias = Sequence[JSONConvertible] # pyright: ignore[reportInvalidTypeForm]
Params: TypeAlias = Mapping[
str, Union[str, bytes, Sequence[str | bytes], JSONObjectConvertible, JSONArrayConvertible]
]

# Regex used to extract the API version from a URL, irrespective of how routes are defined
VERSION_REGEX = re.compile("^\\/v(\\d+)(?:\\.(\\d+))*")

Expand Down Expand Up @@ -196,10 +194,10 @@ def __new__(cls, action_handler: "ActionHandler", *args: Any, **kwargs: Any) ->

def __init__(self, action_handler: "ActionHandler") -> None:
self._action_handler: "ActionHandler" = action_handler
self._path_params: Optional[Controller.PathParams] = None
self._query_params: Optional[Controller.QueryParams] = None
self._form_params: Optional[Controller.FormParams] = None
self._json_params: Optional[Controller.JSONObjectConvertible] = None
self._path_params: Optional[PathParams] = None
self._query_params: Optional[QueryParams] = None
self._form_params: Optional[FormParams] = None
self._json_params: Optional[JSONObjectConvertible] = None
self._major_version: Optional[int] = None
self._minor_version: Optional[int] = None

Expand Down

0 comments on commit f65bf6e

Please sign in to comment.