]> granicus.if.org Git - python/commitdiff
#17040: document that shelve.open() and the Shelf object can be used as context manag...
authorEzio Melotti <ezio.melotti@gmail.com>
Fri, 1 Feb 2013 03:01:50 +0000 (05:01 +0200)
committerEzio Melotti <ezio.melotti@gmail.com>
Fri, 1 Feb 2013 03:01:50 +0000 (05:01 +0200)
Doc/library/shelve.rst

index 9d7d5045e2031626b9e3ef0319bc66ba22a18dfc..b60a54834bf5f94cd960d87fc1c7bc081a389f4b 100644 (file)
@@ -44,8 +44,11 @@ lots of shared  sub-objects.  The keys are ordinary strings.
    .. note::
 
       Do not rely on the shelf being closed automatically; always call
-      :meth:`close` explicitly when you don't need it any more, or use a
-      :keyword:`with` statement with :func:`contextlib.closing`.
+      :meth:`~Shelf.close` explicitly when you don't need it any more, or
+      use :func:`shelve.open` as a context manager::
+
+          with shelve.open('spam') as db:
+              db['eggs'] = 'eggs'
 
 .. warning::
 
@@ -118,10 +121,15 @@ Restrictions
    The *keyencoding* parameter is the encoding used to encode keys before they
    are used with the underlying dict.
 
-   .. versionadded:: 3.2
-      The *keyencoding* parameter; previously, keys were always encoded in
+   :class:`Shelf` objects can also be used as context managers.
+
+   .. versionchanged:: 3.2
+      Added the *keyencoding* parameter; previously, keys were always encoded in
       UTF-8.
 
+   .. versionchanged:: 3.4
+      Added context manager support.
+
 
 .. class:: BsdDbShelf(dict, protocol=None, writeback=False, keyencoding='utf-8')