Rev 5312: Return self from the new context managers so that new objects used with with statements are usable. in http://bazaar.launchpad.net/~lifeless/bzr/contextmanagers

Robert Collins robertc at robertcollins.net
Mon Jun 21 21:03:24 BST 2010


At http://bazaar.launchpad.net/~lifeless/bzr/contextmanagers

------------------------------------------------------------
revno: 5312
revision-id: robertc at robertcollins.net-20100621200323-cq4ue2try98gznq5
parent: pqm at pqm.ubuntu.com-20100621092900-k5hq09vixq5peyqr
committer: Robert Collins <robertc at robertcollins.net>
branch nick: contextmanagers
timestamp: Tue 2010-06-22 08:03:23 +1200
message:
  Return self from the new context managers so that new objects used with with statements are usable.
=== modified file 'bzrlib/__init__.py'
--- a/bzrlib/__init__.py	2010-06-21 04:16:16 +0000
+++ b/bzrlib/__init__.py	2010-06-21 20:03:23 +0000
@@ -164,9 +164,10 @@
         More options may be added in future so callers should use named
         arguments.
 
-        BzrLibraryState implements the Python 2.5 Context Manager protocol, and
-        can be used with the with statement. Upon __enter__ the global
-        variables in use by bzr are set, and they are cleared on __exit__.
+        BzrLibraryState implements the Python 2.5 Context Manager protocol
+        PEP343, and can be used with the with statement. Upon __enter__ the
+        global variables in use by bzr are set, and they are cleared on
+        __exit__.
 
         :param setup_ui: If true (default) use a terminal UI; otherwise 
             some other ui_factory must be assigned to `bzrlib.ui.ui_factory` by
@@ -203,6 +204,7 @@
         global global_state
         self.saved_state = global_state
         global_state = self
+        return self # This is bound to the 'as' clause in a with statement.
 
     def __exit__(self, exc_type, exc_val, exc_tb):
         self.cleanups.cleanup_now()

=== modified file 'bzrlib/ui/__init__.py'
--- a/bzrlib/ui/__init__.py	2010-06-21 03:15:55 +0000
+++ b/bzrlib/ui/__init__.py	2010-06-21 20:03:23 +0000
@@ -132,6 +132,7 @@
         Override in a concrete factory class if initialisation before use is
         needed.
         """
+        return self # This is bound to the 'as' clause in a with statement.
 
     def __exit__(self, exc_type, exc_val, exc_tb):
         """Context manager exit support.




More information about the bazaar-commits mailing list