From bb32ec70e18748bf8bbd1fe1c178aa60a0ec2088 Mon Sep 17 00:00:00 2001 From: Mond WAN Date: Thu, 23 Jul 2020 14:55:53 +0800 Subject: [PATCH] Fix ResourceWarning about unclose file in _get_traceback_files After reading the contents of file, we close it. `with` statement is handy in this situation --- pydump.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pydump.py b/pydump.py index e1418bc..f2c2983 100644 --- a/pydump.py +++ b/pydump.py @@ -192,7 +192,8 @@ def _get_traceback_files(traceback): filename = os.path.abspath(frame.f_code.co_filename) if filename not in files: try: - files[filename] = open(filename).read() + with open(filename) as f: + files[filename] = f.read() except IOError: files[ filename