Skip to content

Commit ee14b33

Browse files
[PR #9777/c5bf5772 backport][3.10] Collapse if block nesting in web.Response (#9778)
Co-authored-by: J. Nick Koston <[email protected]>
1 parent 5a9c2fb commit ee14b33

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
@@ -630,19 +630,17 @@ def __init__(
630630
real_headers[hdrs.CONTENT_TYPE] = content_type + "; charset=" + charset
631631
body = text.encode(charset)
632632
text = None
633-
else:
634-
if hdrs.CONTENT_TYPE in real_headers:
635-
if content_type is not None or charset is not None:
636-
raise ValueError(
637-
"passing both Content-Type header and "
638-
"content_type or charset params "
639-
"is forbidden"
640-
)
641-
else:
642-
if content_type is not None:
643-
if charset is not None:
644-
content_type += "; charset=" + charset
645-
real_headers[hdrs.CONTENT_TYPE] = content_type
633+
elif hdrs.CONTENT_TYPE in real_headers:
634+
if content_type is not None or charset is not None:
635+
raise ValueError(
636+
"passing both Content-Type header and "
637+
"content_type or charset params "
638+
"is forbidden"
639+
)
640+
elif content_type is not None:
641+
if charset is not None:
642+
content_type += "; charset=" + charset
643+
real_headers[hdrs.CONTENT_TYPE] = content_type
646644

647645
super().__init__(status=status, reason=reason, headers=real_headers)
648646

0 commit comments

Comments
 (0)