Change dumps to AnyStr (#2193)

This commit is contained in:
Adam Hopkins 2021-07-19 16:25:36 +03:00 committed by GitHub
parent 7b7a572f9b
commit 94d496afe1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -21,6 +21,7 @@ from traceback import format_exc
from types import SimpleNamespace
from typing import (
Any,
AnyStr,
Awaitable,
Callable,
Coroutine,
@ -138,7 +139,7 @@ class Sanic(BaseSanic):
log_config: Optional[Dict[str, Any]] = None,
configure_logging: bool = True,
register: Optional[bool] = None,
dumps: Optional[Callable[..., str]] = None,
dumps: Optional[Callable[..., AnyStr]] = None,
) -> None:
super().__init__(name=name)
@ -193,7 +194,7 @@ class Sanic(BaseSanic):
self.router.ctx.app = self
if dumps:
BaseHTTPResponse._dumps = dumps
BaseHTTPResponse._dumps = dumps # type: ignore
@property
def loop(self):
@ -737,15 +738,14 @@ class Sanic(BaseSanic):
request.route = route
if (
request.stream.request_body # type: ignore
request.stream
and request.stream.request_body
and not route.ctx.ignore_body
):
if hasattr(handler, "is_stream"):
# Streaming handler: lift the size limit
request.stream.request_max_size = float( # type: ignore
"inf"
)
request.stream.request_max_size = float("inf")
else:
# Non-streaming handler: preload body
await request.receive_body()