[Python-checkins] python/nondist/peps pep-0343.txt,1.2,1.3

gvanrossum@users.sourceforge.net gvanrossum at users.sourceforge.net
Sat May 14 06:02:14 CEST 2005

Update of /cvsroot/python/python/nondist/peps
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9821

Modified Files:
Log Message:
Various clarifications.  Mention Decimal context example.  Clarify
that I don't like having files etc. implement __enter__ and __exit__

Index: pep-0343.txt
RCS file: /cvsroot/python/python/nondist/peps/pep-0343.txt,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- pep-0343.txt	14 May 2005 02:02:40 -0000	1.2
+++ pep-0343.txt	14 May 2005 04:02:10 -0000	1.3
@@ -57,6 +57,10 @@
+    Here, the variables 'abc' and 'exc' are internal variables and not
+    accessible to the user; they will most likely be implemented as
+    special registers or stack positions.
     If the "as VAR" part of the syntax is omitted, the "VAR =" part of
     the translation is omitted (but abc.__enter__() is still called).
@@ -114,6 +118,32 @@
     A robust implementation of such a decorator should be made part of
     the standard library.
+Other Optional Extensions
+    It would be possible to endow certain objects, like files,
+    sockets, and locks, with __enter__ and __exit__ methods so that
+    instead of writing
+        do locking(myLock):
+            BLOCK
+    one could write simply
+        do myLock:
+            BLOCK
+    I think we should be careful with this; it could lead to mistakes
+    like
+        f = open(filename)
+        do f:
+            BLOCK1
+        do f:
+            BLOCK2
+    which does not do what one might think (f is closed when BLOCK2 is
+    entered).
     Several of these examples contain "yield None".  If PEP 342 is
@@ -194,6 +224,10 @@
             do redirecting_stdout(f):
                 print "Hello world"
+       This isn't thread-safe, of course, but neither is doing this
+       same dance manually.  In a single-threaded program (e.g., a
+       script) it is a totally fine way of doing things.
     6. A variant on opening() that also returns an error condition:
@@ -226,6 +260,10 @@
        by default all signals are blocked.  The implementation is left
        as an exercise to the reader.
+    8. Another use for this feature is the Decimal context.  It's left
+       as an exercise for the reader.  (Mail it to me if you'd like to
+       see it here.)
     This document has been placed in the public domain.

More information about the Python-checkins mailing list