From 15a724dfff40ec3b35af2526584e81ff82b4c40b Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Wed, 14 Dec 2016 12:16:34 -0800 Subject: use open() as context manager This uses open() as a context manager instead of calling close() explicitly. This has the advantage of closing even in the event of an exception, being easier to visually inspect for correctness, and being the more modern idiom. This does leave one case of file.close(), where FILE is opened in an if tree. --- alot/db/message.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'alot/db/message.py') diff --git a/alot/db/message.py b/alot/db/message.py index 91a0f420..0a129992 100644 --- a/alot/db/message.py +++ b/alot/db/message.py @@ -70,9 +70,8 @@ class Message(object): "Message file is no longer accessible:\n%s" % path if not self._email: try: - f_mail = open(path) - self._email = message_from_file(f_mail) - f_mail.close() + with open(path) as f: + self._email = message_from_file(f) except IOError: self._email = email.message_from_string(warning) return self._email -- cgit v1.2.3