summaryrefslogtreecommitdiff
path: root/sphinx/pycode
diff options
context:
space:
mode:
Diffstat (limited to 'sphinx/pycode')
-rw-r--r--sphinx/pycode/__init__.py8
-rw-r--r--sphinx/pycode/parser.py2
2 files changed, 5 insertions, 5 deletions
diff --git a/sphinx/pycode/__init__.py b/sphinx/pycode/__init__.py
index 66544f073..de951a19f 100644
--- a/sphinx/pycode/__init__.py
+++ b/sphinx/pycode/__init__.py
@@ -5,7 +5,7 @@
Utilities parsing and analyzing Python code.
- :copyright: Copyright 2007-2017 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2018 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
from __future__ import print_function
@@ -36,11 +36,11 @@ class ModuleAnalyzer(object):
if ('file', filename) in cls.cache:
return cls.cache['file', filename]
try:
- fileobj = open(filename, 'rb')
+ with open(filename, 'rb') as f:
+ obj = cls(f, modname, filename)
+ cls.cache['file', filename] = obj
except Exception as err:
raise PycodeError('error opening %r' % filename, err)
- obj = cls(fileobj, modname, filename)
- cls.cache['file', filename] = obj
return obj
@classmethod
diff --git a/sphinx/pycode/parser.py b/sphinx/pycode/parser.py
index 7460dcfce..9aed7f7f4 100644
--- a/sphinx/pycode/parser.py
+++ b/sphinx/pycode/parser.py
@@ -5,7 +5,7 @@
Utilities parsing and analyzing Python code.
- :copyright: Copyright 2007-2017 by the Sphinx team, see AUTHORS.
+ :copyright: Copyright 2007-2018 by the Sphinx team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
import re