diff options
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | modutils.py | 5 |
2 files changed, 9 insertions, 3 deletions
@@ -2,8 +2,11 @@ ChangeLog for logilab.common ============================ -- - * modutils: don't propagate IOError when package's __init__.py file doesn't - exist (#174606) + * modutils: + * don't propagate IOError when package's __init__.py file doesn't + exist (#174606) + * ensure file is closed, may cause pb depending on the interpreter, eg + pypy) (#180876) * fix some cases of failing python3 install on windows platform / cross compilation (#180836) diff --git a/modutils.py b/modutils.py index e9615d5..e339a70 100644 --- a/modutils.py +++ b/modutils.py @@ -27,6 +27,8 @@ :type BUILTIN_MODULES: dict :var BUILTIN_MODULES: dictionary with builtin module names has key """ +from __future__ import with_statement + __docformat__ = "restructuredtext en" import sys @@ -657,7 +659,8 @@ def _module_file(modpath, path=None): # XXX guess if package is using pkgutil.extend_path by looking for # those keywords in the first four Kbytes try: - data = open(join(mp_filename, '__init__.py')).read(4096) + with open(join(mp_filename, '__init__.py')) as stream: + data = stream.read(4096) except IOError: path = [mp_filename] else: |