From 7a17001df4de919c4b1b56f3b8cc51c6d0a36c16 Mon Sep 17 00:00:00 2001 From: Lisandro Dalcin Date: Thu, 16 Dec 2010 13:48:38 -0300 Subject: [PATCH] fix ResourceWarning about unclosed files in Py 3.2 --- Cython/Build/Dependencies.py | 6 +++++- Cython/Build/Inline.py | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Cython/Build/Dependencies.py b/Cython/Build/Dependencies.py index 05c5035f..73b03342 100644 --- a/Cython/Build/Dependencies.py +++ b/Cython/Build/Dependencies.py @@ -220,7 +220,11 @@ def parse_dependencies(source_filename): # Actual parsing is way to slow, so we use regular expressions. # The only catch is that we must strip comments and string # literals ahead of time. - source = Utils.open_source_file(source_filename, "rU").read() + fh = Utils.open_source_file(source_filename, "rU") + try: + source = fh.read() + finally: + fh.close() distutils_info = DistutilsInfo(source) source, literals = strip_string_literals(source) source = source.replace('\\\n', ' ') diff --git a/Cython/Build/Inline.py b/Cython/Build/Inline.py index 622bc61b..2c6db326 100644 --- a/Cython/Build/Inline.py +++ b/Cython/Build/Inline.py @@ -163,7 +163,11 @@ def __invoke(%(params)s): for key, value in literals.items(): module_code = module_code.replace(key, value) pyx_file = os.path.join(lib_dir, module_name + '.pyx') - open(pyx_file, 'w').write(module_code) + fh = open(pyx_file, 'w') + try: + fh.write(module_code) + finally: + fh.close() extension = Extension( name = module_name, sources = [pyx_file], -- 2.26.2