[Python-checkins] cpython (3.3): I was confused before. It's correct to not call .close() inside the with
barry.warsaw
python-checkins at python.org
Fri May 10 17:36:29 CEST 2013
http://hg.python.org/cpython/rev/3b935ac07f65
changeset: 83704:3b935ac07f65
branch: 3.3
parent: 83702:ead47bc3a763
user: Barry Warsaw <barry at python.org>
date: Fri May 10 11:35:38 2013 -0400
summary:
I was confused before. It's correct to not call .close() inside the with
statement, but add a comment that clarifies the purpose of the code.
files:
Doc/library/contextlib.rst | 5 +++--
1 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/Doc/library/contextlib.rst b/Doc/library/contextlib.rst
--- a/Doc/library/contextlib.rst
+++ b/Doc/library/contextlib.rst
@@ -259,11 +259,12 @@
with ExitStack() as stack:
files = [stack.enter_context(open(fname)) for fname in filenames]
- close_files = stack.pop_all().close()
+ # Hold onto the close method, but don't call it yet.
+ close_files = stack.pop_all().close
# If opening any file fails, all previously opened files will be
# closed automatically. If all files are opened successfully,
# they will remain open even after the with statement ends.
- # close_files() can then be invoked explicitly to close them all
+ # close_files() can then be invoked explicitly to close them all.
.. method:: close()
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list