More proper closing of files
diff --git a/Lib/doctest.py b/Lib/doctest.py
index e15f704..5d186b5 100644
--- a/Lib/doctest.py
+++ b/Lib/doctest.py
@@ -214,7 +214,8 @@
                 # get_data() opens files as 'rb', so one must do the equivalent
                 # conversion as universal newlines would do.
                 return file_contents.replace(os.linesep, '\n'), filename
-    return open(filename, encoding=encoding).read(), filename
+    with open(filename, encoding=encoding) as f:
+        return f.read(), filename
 
 def _indent(s, indent=4):
     """
@@ -2523,7 +2524,8 @@
 
         if pm:
             try:
-                exec(open(srcfilename).read(), globs, globs)
+                with open(srcfilename) as f:
+                    exec(f.read(), globs, globs)
             except:
                 print(sys.exc_info()[1])
                 pdb.post_mortem(sys.exc_info()[2])