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:
Erik Montnemery 2021-11-17 09:07:01 +01:00 committed by GitHub
parent 593bc866f0
commit dec54488e8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 31 additions and 29 deletions

View file

@ -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),
}