summaryrefslogtreecommitdiffstats
path: root/Lib/doctest.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2010-10-14 22:11:44 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2010-10-14 22:11:44 (GMT)
commit92f60ed82a302035009835a8d63ff714118a96ad (patch)
treea119000028c02ecf0317859d0bcda37fe4c505b4 /Lib/doctest.py
parent73315e92009c88acf53e497a0b9fcd93cd735aed (diff)
downloadcpython-92f60ed82a302035009835a8d63ff714118a96ad.zip
cpython-92f60ed82a302035009835a8d63ff714118a96ad.tar.gz
cpython-92f60ed82a302035009835a8d63ff714118a96ad.tar.bz2
More proper closing of files
Diffstat (limited to 'Lib/doctest.py')
-rw-r--r--Lib/doctest.py6
1 files changed, 4 insertions, 2 deletions
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 @@ def _load_testfile(filename, package, module_relative, encoding):
# 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 @@ def debug_script(src, pm=False, globs=None):
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])