Skip to content

Commit d2ec42e

Browse files
[PR #9777/c5bf5772 backport][3.11] Collapse if block nesting in web.Response (#9779)
Co-authored-by: J. Nick Koston <[email protected]>
1 parent c206faf commit d2ec42e

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

aiohttp/web_response.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -647,19 +647,17 @@ def __init__(
647647
real_headers[hdrs.CONTENT_TYPE] = content_type + "; charset=" + charset
648648
body = text.encode(charset)
649649
text = None
650-
else:
651-
if hdrs.CONTENT_TYPE in real_headers:
652-
if content_type is not None or charset is not None:
653-
raise ValueError(
654-
"passing both Content-Type header and "
655-
"content_type or charset params "
656-
"is forbidden"
657-
)
658-
else:
659-
if content_type is not None:
660-
if charset is not None:
661-
content_type += "; charset=" + charset
662-
real_headers[hdrs.CONTENT_TYPE] = content_type
650+
elif hdrs.CONTENT_TYPE in real_headers:
651+
if content_type is not None or charset is not None:
652+
raise ValueError(
653+
"passing both Content-Type header and "
654+
"content_type or charset params "
655+
"is forbidden"
656+
)
657+
elif content_type is not None:
658+
if charset is not None:
659+
content_type += "; charset=" + charset
660+
real_headers[hdrs.CONTENT_TYPE] = content_type
663661

664662
super().__init__(status=status, reason=reason, headers=real_headers)
665663

0 commit comments

Comments
 (0)