python: Close opened files.

Fixes various instances of ‘ResourceWarning: unclosed file’ with
python -Wd.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2020-10-24 00:33:54 -07:00
committed by Tim Abbott
parent bb2db31f29
commit 31d0141a30
16 changed files with 156 additions and 134 deletions

View File

@@ -37,7 +37,8 @@ From image editing program:
"""
def set_avatar(self, user: UserProfile, filename: str) -> None:
upload_avatar_image(open(filename, 'rb'), user, user)
with open(filename, 'rb') as f:
upload_avatar_image(f, user, user)
do_change_avatar_fields(user, UserProfile.AVATAR_FROM_USER, acting_user=None)
def add_message_formatting_conversation(self) -> None: