Resolve typing of stacked route definitions (#2455)
This commit is contained in:
parent
1668e1532f
commit
a411bc06e3
@ -8,7 +8,17 @@ from pathlib import PurePath
|
|||||||
from re import sub
|
from re import sub
|
||||||
from textwrap import dedent
|
from textwrap import dedent
|
||||||
from time import gmtime, strftime
|
from time import gmtime, strftime
|
||||||
from typing import Any, Callable, Iterable, List, Optional, Set, Tuple, Union
|
from typing import (
|
||||||
|
Any,
|
||||||
|
Callable,
|
||||||
|
Iterable,
|
||||||
|
List,
|
||||||
|
Optional,
|
||||||
|
Set,
|
||||||
|
Tuple,
|
||||||
|
Union,
|
||||||
|
cast,
|
||||||
|
)
|
||||||
from urllib.parse import unquote
|
from urllib.parse import unquote
|
||||||
|
|
||||||
from sanic_routing.route import Route # type: ignore
|
from sanic_routing.route import Route # type: ignore
|
||||||
@ -283,7 +293,7 @@ class RouteMixin(metaclass=SanicMeta):
|
|||||||
version_prefix: str = "/v",
|
version_prefix: str = "/v",
|
||||||
error_format: Optional[str] = None,
|
error_format: Optional[str] = None,
|
||||||
**ctx_kwargs,
|
**ctx_kwargs,
|
||||||
) -> RouteWrapper:
|
) -> RouteHandler:
|
||||||
"""
|
"""
|
||||||
Add an API URL under the **GET** *HTTP* method
|
Add an API URL under the **GET** *HTTP* method
|
||||||
|
|
||||||
@ -299,17 +309,20 @@ class RouteMixin(metaclass=SanicMeta):
|
|||||||
will be appended to the route context (``route.ctx``)
|
will be appended to the route context (``route.ctx``)
|
||||||
:return: Object decorated with :func:`route` method
|
:return: Object decorated with :func:`route` method
|
||||||
"""
|
"""
|
||||||
return self.route(
|
return cast(
|
||||||
uri,
|
RouteHandler,
|
||||||
methods=frozenset({"GET"}),
|
self.route(
|
||||||
host=host,
|
uri,
|
||||||
strict_slashes=strict_slashes,
|
methods=frozenset({"GET"}),
|
||||||
version=version,
|
host=host,
|
||||||
name=name,
|
strict_slashes=strict_slashes,
|
||||||
ignore_body=ignore_body,
|
version=version,
|
||||||
version_prefix=version_prefix,
|
name=name,
|
||||||
error_format=error_format,
|
ignore_body=ignore_body,
|
||||||
**ctx_kwargs,
|
version_prefix=version_prefix,
|
||||||
|
error_format=error_format,
|
||||||
|
**ctx_kwargs,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
def post(
|
def post(
|
||||||
@ -323,7 +336,7 @@ class RouteMixin(metaclass=SanicMeta):
|
|||||||
version_prefix: str = "/v",
|
version_prefix: str = "/v",
|
||||||
error_format: Optional[str] = None,
|
error_format: Optional[str] = None,
|
||||||
**ctx_kwargs,
|
**ctx_kwargs,
|
||||||
) -> RouteWrapper:
|
) -> RouteHandler:
|
||||||
"""
|
"""
|
||||||
Add an API URL under the **POST** *HTTP* method
|
Add an API URL under the **POST** *HTTP* method
|
||||||
|
|
||||||
@ -339,17 +352,20 @@ class RouteMixin(metaclass=SanicMeta):
|
|||||||
will be appended to the route context (``route.ctx``)
|
will be appended to the route context (``route.ctx``)
|
||||||
:return: Object decorated with :func:`route` method
|
:return: Object decorated with :func:`route` method
|
||||||
"""
|
"""
|
||||||
return self.route(
|
return cast(
|
||||||
uri,
|
RouteHandler,
|
||||||
methods=frozenset({"POST"}),
|
self.route(
|
||||||
host=host,
|
uri,
|
||||||
strict_slashes=strict_slashes,
|
methods=frozenset({"POST"}),
|
||||||
stream=stream,
|
host=host,
|
||||||
version=version,
|
strict_slashes=strict_slashes,
|
||||||
name=name,
|
stream=stream,
|
||||||
version_prefix=version_prefix,
|
version=version,
|
||||||
error_format=error_format,
|
name=name,
|
||||||
**ctx_kwargs,
|
version_prefix=version_prefix,
|
||||||
|
error_format=error_format,
|
||||||
|
**ctx_kwargs,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
def put(
|
def put(
|
||||||
@ -363,7 +379,7 @@ class RouteMixin(metaclass=SanicMeta):
|
|||||||
version_prefix: str = "/v",
|
version_prefix: str = "/v",
|
||||||
error_format: Optional[str] = None,
|
error_format: Optional[str] = None,
|
||||||
**ctx_kwargs,
|
**ctx_kwargs,
|
||||||
) -> RouteWrapper:
|
) -> RouteHandler:
|
||||||
"""
|
"""
|
||||||
Add an API URL under the **PUT** *HTTP* method
|
Add an API URL under the **PUT** *HTTP* method
|
||||||
|
|
||||||
@ -379,17 +395,20 @@ class RouteMixin(metaclass=SanicMeta):
|
|||||||
will be appended to the route context (``route.ctx``)
|
will be appended to the route context (``route.ctx``)
|
||||||
:return: Object decorated with :func:`route` method
|
:return: Object decorated with :func:`route` method
|
||||||
"""
|
"""
|
||||||
return self.route(
|
return cast(
|
||||||
uri,
|
RouteHandler,
|
||||||
methods=frozenset({"PUT"}),
|
self.route(
|
||||||
host=host,
|
uri,
|
||||||
strict_slashes=strict_slashes,
|
methods=frozenset({"PUT"}),
|
||||||
stream=stream,
|
host=host,
|
||||||
version=version,
|
strict_slashes=strict_slashes,
|
||||||
name=name,
|
stream=stream,
|
||||||
version_prefix=version_prefix,
|
version=version,
|
||||||
error_format=error_format,
|
name=name,
|
||||||
**ctx_kwargs,
|
version_prefix=version_prefix,
|
||||||
|
error_format=error_format,
|
||||||
|
**ctx_kwargs,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
def head(
|
def head(
|
||||||
@ -403,7 +422,7 @@ class RouteMixin(metaclass=SanicMeta):
|
|||||||
version_prefix: str = "/v",
|
version_prefix: str = "/v",
|
||||||
error_format: Optional[str] = None,
|
error_format: Optional[str] = None,
|
||||||
**ctx_kwargs,
|
**ctx_kwargs,
|
||||||
) -> RouteWrapper:
|
) -> RouteHandler:
|
||||||
"""
|
"""
|
||||||
Add an API URL under the **HEAD** *HTTP* method
|
Add an API URL under the **HEAD** *HTTP* method
|
||||||
|
|
||||||
@ -427,17 +446,20 @@ class RouteMixin(metaclass=SanicMeta):
|
|||||||
will be appended to the route context (``route.ctx``)
|
will be appended to the route context (``route.ctx``)
|
||||||
:return: Object decorated with :func:`route` method
|
:return: Object decorated with :func:`route` method
|
||||||
"""
|
"""
|
||||||
return self.route(
|
return cast(
|
||||||
uri,
|
RouteHandler,
|
||||||
methods=frozenset({"HEAD"}),
|
self.route(
|
||||||
host=host,
|
uri,
|
||||||
strict_slashes=strict_slashes,
|
methods=frozenset({"HEAD"}),
|
||||||
version=version,
|
host=host,
|
||||||
name=name,
|
strict_slashes=strict_slashes,
|
||||||
ignore_body=ignore_body,
|
version=version,
|
||||||
version_prefix=version_prefix,
|
name=name,
|
||||||
error_format=error_format,
|
ignore_body=ignore_body,
|
||||||
**ctx_kwargs,
|
version_prefix=version_prefix,
|
||||||
|
error_format=error_format,
|
||||||
|
**ctx_kwargs,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
def options(
|
def options(
|
||||||
@ -451,7 +473,7 @@ class RouteMixin(metaclass=SanicMeta):
|
|||||||
version_prefix: str = "/v",
|
version_prefix: str = "/v",
|
||||||
error_format: Optional[str] = None,
|
error_format: Optional[str] = None,
|
||||||
**ctx_kwargs,
|
**ctx_kwargs,
|
||||||
) -> RouteWrapper:
|
) -> RouteHandler:
|
||||||
"""
|
"""
|
||||||
Add an API URL under the **OPTIONS** *HTTP* method
|
Add an API URL under the **OPTIONS** *HTTP* method
|
||||||
|
|
||||||
@ -475,17 +497,20 @@ class RouteMixin(metaclass=SanicMeta):
|
|||||||
will be appended to the route context (``route.ctx``)
|
will be appended to the route context (``route.ctx``)
|
||||||
:return: Object decorated with :func:`route` method
|
:return: Object decorated with :func:`route` method
|
||||||
"""
|
"""
|
||||||
return self.route(
|
return cast(
|
||||||
uri,
|
RouteHandler,
|
||||||
methods=frozenset({"OPTIONS"}),
|
self.route(
|
||||||
host=host,
|
uri,
|
||||||
strict_slashes=strict_slashes,
|
methods=frozenset({"OPTIONS"}),
|
||||||
version=version,
|
host=host,
|
||||||
name=name,
|
strict_slashes=strict_slashes,
|
||||||
ignore_body=ignore_body,
|
version=version,
|
||||||
version_prefix=version_prefix,
|
name=name,
|
||||||
error_format=error_format,
|
ignore_body=ignore_body,
|
||||||
**ctx_kwargs,
|
version_prefix=version_prefix,
|
||||||
|
error_format=error_format,
|
||||||
|
**ctx_kwargs,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
def patch(
|
def patch(
|
||||||
@ -499,7 +524,7 @@ class RouteMixin(metaclass=SanicMeta):
|
|||||||
version_prefix: str = "/v",
|
version_prefix: str = "/v",
|
||||||
error_format: Optional[str] = None,
|
error_format: Optional[str] = None,
|
||||||
**ctx_kwargs,
|
**ctx_kwargs,
|
||||||
) -> RouteWrapper:
|
) -> RouteHandler:
|
||||||
"""
|
"""
|
||||||
Add an API URL under the **PATCH** *HTTP* method
|
Add an API URL under the **PATCH** *HTTP* method
|
||||||
|
|
||||||
@ -525,17 +550,20 @@ class RouteMixin(metaclass=SanicMeta):
|
|||||||
will be appended to the route context (``route.ctx``)
|
will be appended to the route context (``route.ctx``)
|
||||||
:return: Object decorated with :func:`route` method
|
:return: Object decorated with :func:`route` method
|
||||||
"""
|
"""
|
||||||
return self.route(
|
return cast(
|
||||||
uri,
|
RouteHandler,
|
||||||
methods=frozenset({"PATCH"}),
|
self.route(
|
||||||
host=host,
|
uri,
|
||||||
strict_slashes=strict_slashes,
|
methods=frozenset({"PATCH"}),
|
||||||
stream=stream,
|
host=host,
|
||||||
version=version,
|
strict_slashes=strict_slashes,
|
||||||
name=name,
|
stream=stream,
|
||||||
version_prefix=version_prefix,
|
version=version,
|
||||||
error_format=error_format,
|
name=name,
|
||||||
**ctx_kwargs,
|
version_prefix=version_prefix,
|
||||||
|
error_format=error_format,
|
||||||
|
**ctx_kwargs,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
def delete(
|
def delete(
|
||||||
@ -549,7 +577,7 @@ class RouteMixin(metaclass=SanicMeta):
|
|||||||
version_prefix: str = "/v",
|
version_prefix: str = "/v",
|
||||||
error_format: Optional[str] = None,
|
error_format: Optional[str] = None,
|
||||||
**ctx_kwargs,
|
**ctx_kwargs,
|
||||||
) -> RouteWrapper:
|
) -> RouteHandler:
|
||||||
"""
|
"""
|
||||||
Add an API URL under the **DELETE** *HTTP* method
|
Add an API URL under the **DELETE** *HTTP* method
|
||||||
|
|
||||||
@ -565,17 +593,20 @@ class RouteMixin(metaclass=SanicMeta):
|
|||||||
will be appended to the route context (``route.ctx``)
|
will be appended to the route context (``route.ctx``)
|
||||||
:return: Object decorated with :func:`route` method
|
:return: Object decorated with :func:`route` method
|
||||||
"""
|
"""
|
||||||
return self.route(
|
return cast(
|
||||||
uri,
|
RouteHandler,
|
||||||
methods=frozenset({"DELETE"}),
|
self.route(
|
||||||
host=host,
|
uri,
|
||||||
strict_slashes=strict_slashes,
|
methods=frozenset({"DELETE"}),
|
||||||
version=version,
|
host=host,
|
||||||
name=name,
|
strict_slashes=strict_slashes,
|
||||||
ignore_body=ignore_body,
|
version=version,
|
||||||
version_prefix=version_prefix,
|
name=name,
|
||||||
error_format=error_format,
|
ignore_body=ignore_body,
|
||||||
**ctx_kwargs,
|
version_prefix=version_prefix,
|
||||||
|
error_format=error_format,
|
||||||
|
**ctx_kwargs,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
def websocket(
|
def websocket(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user