Enable basic type checking for cloud (#55337)
* Enable basic type checking for cloud * Update mypy settings * Address review comment * Fix rebase mistakes * Correct decorator order
This commit is contained in:
parent
593bc866f0
commit
dec54488e8
6 changed files with 31 additions and 29 deletions
|
@ -9,13 +9,17 @@ from aiohttp import payload, web
|
|||
def aiohttp_serialize_response(response: web.Response) -> dict[str, Any]:
|
||||
"""Serialize an aiohttp response to a dictionary."""
|
||||
if (body := response.body) is None:
|
||||
pass
|
||||
body_decoded = None
|
||||
elif isinstance(body, payload.StringPayload):
|
||||
# pylint: disable=protected-access
|
||||
body = body._value.decode(body.encoding)
|
||||
body_decoded = body._value.decode(body.encoding)
|
||||
elif isinstance(body, bytes):
|
||||
body = body.decode(response.charset or "utf-8")
|
||||
body_decoded = body.decode(response.charset or "utf-8")
|
||||
else:
|
||||
raise ValueError("Unknown payload encoding")
|
||||
|
||||
return {"status": response.status, "body": body, "headers": dict(response.headers)}
|
||||
return {
|
||||
"status": response.status,
|
||||
"body": body_decoded,
|
||||
"headers": dict(response.headers),
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue