This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: PEP 343 with statement
Type: Stage:
Components: Interpreter Core Versions: Python 2.5
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: gvanrossum Nosy List: gvanrossum, vuduchyl
Priority: normal Keywords: patch

Created on 2006-02-21 08:05 by vuduchyl, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
mbland-pep343-r42536.patch vuduchyl, 2006-02-21 08:05 PEP 343 with statement implementation
with.diff gvanrossum, 2006-02-27 21:42 Guido's version (no __future__ yet, nor docs)
Messages (4)
msg49555 - (view) Author: mbland (vuduchyl) Date: 2006-02-21 08:05
With Neal Norwitz's help, I've developed this patch
which implements the with statement from PEP 343.  I
still need to flesh out the documentation, and the
contextmanager.py and nested.py files (copied almost
verbatim from the PEP) are very bare-bones, but the
with syntax itself is accompanied by a rather extensive
test.

Most of the patch reflects changes in automatically
generated files.  The most extensive changes were in
Python/ast.c and Python/compile.c, and the test resides
in Lib/test/with_test.py.

I'm very open to comments and suggestions, particularly
with regards to the contortions in compiler_with() in
Python/compile.c.

Also, a few questions regarding the PEP itself:

- Should the grammar be strict about not allowing
extraneous parentheses around "(NAME)" in the
with_var_name rule (Grammar/Grammar)?

- Should "(NAME ,)" (note the trailing comma) be a
valid VAR list?  Compared with the rule for global, the
current definition seems to suffice, but (according to
Neal) seems inconsistent in the light of typical tuple
syntax.

- Should VAR names that are not instantiated prior to
the with statement exist after exiting the scope of the
with statement?

Thanks,

Mike
msg49556 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2006-02-27 21:42
Logged In: YES 
user_id=6380

Thanks Mike!  I'm uploading a much improved version, mostly
for the benefit of Thomas.  I plan to check this in soon,
even though it doesn't have the __future__ statement or docs
yet.

I'm also moving nested.py and contextmanager.py into
Lib/test; the PEP was ambiguous but there was no plan to
make these part of the standard library yet.  (Only locks,
files and decimal will get context managers.)
msg49557 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2006-02-27 22:39
Logged In: YES 
user_id=6380

I'm closing this patch, since I've checked in most of the work.

Thomas is working on the __future__ statement.

We still need docs.  Mike, if you are working on those, just
email them to me or Neal for checkin.
msg49558 - (view) Author: mbland (vuduchyl) Date: 2006-02-28 07:41
Logged In: YES 
user_id=1339184

Sure, I'll work up some doc patches--hopefully by the end of
the week, this weekend fer sure.
History
Date User Action Args
2022-04-11 14:56:15adminsetgithub: 42928
2006-02-21 08:05:33vuduchylcreate