style: add some type hints (#2517)
This commit is contained in:
parent
9cf38a0a83
commit
dee09d7fff
|
@ -1184,7 +1184,7 @@ class Sanic(BaseSanic, RunnerMixin, metaclass=TouchUpMeta):
|
|||
*,
|
||||
name: Optional[str] = None,
|
||||
register: bool = True,
|
||||
) -> Optional[Task]:
|
||||
) -> Optional[Task[Any]]:
|
||||
"""
|
||||
Schedule a task to run later, after the loop has started.
|
||||
Different from asyncio.ensure_future in that it does not
|
||||
|
|
|
@ -127,19 +127,19 @@ class Config(dict, metaclass=DescriptorMeta):
|
|||
self._check_error_format()
|
||||
self._init = True
|
||||
|
||||
def __getattr__(self, attr):
|
||||
def __getattr__(self, attr: Any):
|
||||
try:
|
||||
return self[attr]
|
||||
except KeyError as ke:
|
||||
raise AttributeError(f"Config has no '{ke.args[0]}'")
|
||||
|
||||
def __setattr__(self, attr, value) -> None:
|
||||
def __setattr__(self, attr: str, value: Any) -> None:
|
||||
self.update({attr: value})
|
||||
|
||||
def __setitem__(self, attr, value) -> None:
|
||||
def __setitem__(self, attr: str, value: Any) -> None:
|
||||
self.update({attr: value})
|
||||
|
||||
def update(self, *other, **kwargs) -> None:
|
||||
def update(self, *other: Any, **kwargs: Any) -> None:
|
||||
kwargs.update({k: v for item in other for k, v in dict(item).items()})
|
||||
setters: Dict[str, Any] = {
|
||||
k: kwargs.pop(k)
|
||||
|
|
|
@ -225,7 +225,7 @@ class RouteMixin(metaclass=SanicMeta):
|
|||
stream: bool = False,
|
||||
version_prefix: str = "/v",
|
||||
error_format: Optional[str] = None,
|
||||
**ctx_kwargs,
|
||||
**ctx_kwargs: Any,
|
||||
) -> RouteHandler:
|
||||
"""A helper method to register class instance or
|
||||
functions as a handler to the application url
|
||||
|
@ -286,7 +286,7 @@ class RouteMixin(metaclass=SanicMeta):
|
|||
ignore_body: bool = True,
|
||||
version_prefix: str = "/v",
|
||||
error_format: Optional[str] = None,
|
||||
**ctx_kwargs,
|
||||
**ctx_kwargs: Any,
|
||||
) -> RouteHandler:
|
||||
"""
|
||||
Add an API URL under the **GET** *HTTP* method
|
||||
|
@ -329,7 +329,7 @@ class RouteMixin(metaclass=SanicMeta):
|
|||
name: Optional[str] = None,
|
||||
version_prefix: str = "/v",
|
||||
error_format: Optional[str] = None,
|
||||
**ctx_kwargs,
|
||||
**ctx_kwargs: Any,
|
||||
) -> RouteHandler:
|
||||
"""
|
||||
Add an API URL under the **POST** *HTTP* method
|
||||
|
@ -372,7 +372,7 @@ class RouteMixin(metaclass=SanicMeta):
|
|||
name: Optional[str] = None,
|
||||
version_prefix: str = "/v",
|
||||
error_format: Optional[str] = None,
|
||||
**ctx_kwargs,
|
||||
**ctx_kwargs: Any,
|
||||
) -> RouteHandler:
|
||||
"""
|
||||
Add an API URL under the **PUT** *HTTP* method
|
||||
|
@ -415,7 +415,7 @@ class RouteMixin(metaclass=SanicMeta):
|
|||
ignore_body: bool = True,
|
||||
version_prefix: str = "/v",
|
||||
error_format: Optional[str] = None,
|
||||
**ctx_kwargs,
|
||||
**ctx_kwargs: Any,
|
||||
) -> RouteHandler:
|
||||
"""
|
||||
Add an API URL under the **HEAD** *HTTP* method
|
||||
|
@ -466,7 +466,7 @@ class RouteMixin(metaclass=SanicMeta):
|
|||
ignore_body: bool = True,
|
||||
version_prefix: str = "/v",
|
||||
error_format: Optional[str] = None,
|
||||
**ctx_kwargs,
|
||||
**ctx_kwargs: Any,
|
||||
) -> RouteHandler:
|
||||
"""
|
||||
Add an API URL under the **OPTIONS** *HTTP* method
|
||||
|
@ -517,7 +517,7 @@ class RouteMixin(metaclass=SanicMeta):
|
|||
name: Optional[str] = None,
|
||||
version_prefix: str = "/v",
|
||||
error_format: Optional[str] = None,
|
||||
**ctx_kwargs,
|
||||
**ctx_kwargs: Any,
|
||||
) -> RouteHandler:
|
||||
"""
|
||||
Add an API URL under the **PATCH** *HTTP* method
|
||||
|
@ -570,7 +570,7 @@ class RouteMixin(metaclass=SanicMeta):
|
|||
ignore_body: bool = True,
|
||||
version_prefix: str = "/v",
|
||||
error_format: Optional[str] = None,
|
||||
**ctx_kwargs,
|
||||
**ctx_kwargs: Any,
|
||||
) -> RouteHandler:
|
||||
"""
|
||||
Add an API URL under the **DELETE** *HTTP* method
|
||||
|
@ -614,7 +614,7 @@ class RouteMixin(metaclass=SanicMeta):
|
|||
apply: bool = True,
|
||||
version_prefix: str = "/v",
|
||||
error_format: Optional[str] = None,
|
||||
**ctx_kwargs,
|
||||
**ctx_kwargs: Any,
|
||||
):
|
||||
"""
|
||||
Decorate a function to be registered as a websocket route
|
||||
|
@ -658,7 +658,7 @@ class RouteMixin(metaclass=SanicMeta):
|
|||
name: Optional[str] = None,
|
||||
version_prefix: str = "/v",
|
||||
error_format: Optional[str] = None,
|
||||
**ctx_kwargs,
|
||||
**ctx_kwargs: Any,
|
||||
):
|
||||
"""
|
||||
A helper method to register a function as a websocket route.
|
||||
|
@ -695,18 +695,18 @@ class RouteMixin(metaclass=SanicMeta):
|
|||
|
||||
def static(
|
||||
self,
|
||||
uri,
|
||||
uri: str,
|
||||
file_or_directory: Union[str, bytes, PurePath],
|
||||
pattern=r"/?.+",
|
||||
use_modified_since=True,
|
||||
use_content_range=False,
|
||||
stream_large_files=False,
|
||||
name="static",
|
||||
host=None,
|
||||
strict_slashes=None,
|
||||
content_type=None,
|
||||
apply=True,
|
||||
resource_type=None,
|
||||
pattern: str = r"/?.+",
|
||||
use_modified_since: bool = True,
|
||||
use_content_range: bool = False,
|
||||
stream_large_files: bool = False,
|
||||
name: str = "static",
|
||||
host: Optional[str] = None,
|
||||
strict_slashes: Optional[bool] = None,
|
||||
content_type: Optional[bool] = None,
|
||||
apply: bool = True,
|
||||
resource_type: Optional[str] = None,
|
||||
):
|
||||
"""
|
||||
Register a root to serve files from. The input can either be a
|
||||
|
|
|
@ -210,7 +210,7 @@ class HTTPResponse(BaseHTTPResponse):
|
|||
|
||||
|
||||
def empty(
|
||||
status=204, headers: Optional[Dict[str, str]] = None
|
||||
status: int = 204, headers: Optional[Dict[str, str]] = None
|
||||
) -> HTTPResponse:
|
||||
"""
|
||||
Returns an empty response to the client.
|
||||
|
@ -227,7 +227,7 @@ def json(
|
|||
headers: Optional[Dict[str, str]] = None,
|
||||
content_type: str = "application/json",
|
||||
dumps: Optional[Callable[..., str]] = None,
|
||||
**kwargs,
|
||||
**kwargs: Any,
|
||||
) -> HTTPResponse:
|
||||
"""
|
||||
Returns response object with body in json format.
|
||||
|
|
Loading…
Reference in New Issue
Block a user