[Python-checkins] python/nondist/peps pep-0343.txt,1.5,1.6

gvanrossum@users.sourceforge.net gvanrossum at users.sourceforge.net
Sat May 14 07:18:38 CEST 2005


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

Modified Files:
	pep-0343.txt 
Log Message:
Explain the __exit__() signature.


Index: pep-0343.txt
===================================================================
RCS file: /cvsroot/python/python/nondist/peps/pep-0343.txt,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- pep-0343.txt	14 May 2005 05:08:23 -0000	1.5
+++ pep-0343.txt	14 May 2005 05:18:36 -0000	1.6
@@ -185,6 +185,23 @@
     with three arguments representing the exception type, value, and
     traceback.
 
+    The motivation for this API to __exit__(), as opposed to the
+    argument-less __exit__() from PEP 310, was given by the
+    transactional() use case, example 3 below.  The template in that
+    example must commit or roll back the transaction depending on
+    whether an exception occurred or not.  Rather than just having a
+    boolean flag indicating whether an exception occurred, we pass the
+    complete exception information, for the benefor of an
+    exception-logging facility for example.  Relying on sys.exc_info()
+    to get att the exception information was rejected; sys.exc_info()
+    has very complex semantics and it is perfectly possible that it
+    returns the exception information for an exception that was caught
+    ages ago.  It was also proposed to add an additional boolean to
+    distinguish between reaching the end of BLOCK and a non-local
+    goto.  This was rejected as too complex and unnecessary; a
+    non-local goto should be considered unexceptional for the purposes
+    of a database transaction roll-back decision.
+
 Optional Generator Decorator
 
     It is possible to write a decorator that makes it possible to use
@@ -300,7 +317,7 @@
             def __init__(self, db):
                 self.db = db
             def __enter__(self):
-                pass
+                self.db.begin()
             def __exit__(self, *args):
                 if args and args[0] is not None:
                     self.db.rollback()



More information about the Python-checkins mailing list