summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorEzio Melotti <ezio.melotti@gmail.com>2013-02-01 03:01:50 (GMT)
committerEzio Melotti <ezio.melotti@gmail.com>2013-02-01 03:01:50 (GMT)
commitd23c0a89926570b237013bd60dc31125c07b46cf (patch)
treec8b81b6d8f1ced7a4dd9412a858e6e7c586ff192 /Doc
parent894499fa27552cc8587e1a41e2ff1298ed0d45d5 (diff)
downloadcpython-d23c0a89926570b237013bd60dc31125c07b46cf.zip
cpython-d23c0a89926570b237013bd60dc31125c07b46cf.tar.gz
cpython-d23c0a89926570b237013bd60dc31125c07b46cf.tar.bz2
#17040: document that shelve.open() and the Shelf object can be used as context managers. Initial patch by Berker Peksag.
Diffstat (limited to 'Doc')
-rw-r--r--Doc/library/shelve.rst16
1 files changed, 12 insertions, 4 deletions
diff --git a/Doc/library/shelve.rst b/Doc/library/shelve.rst
index 9d7d504..b60a548 100644
--- a/Doc/library/shelve.rst
+++ b/Doc/library/shelve.rst
@@ -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')