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