]> granicus.if.org Git - python/commitdiff
Issue 5754: tweak shelve doc wording to make it clearer that even when
authorR. David Murray <rdmurray@bitdance.com>
Thu, 11 Feb 2010 01:38:42 +0000 (01:38 +0000)
committerR. David Murray <rdmurray@bitdance.com>
Thu, 11 Feb 2010 01:38:42 +0000 (01:38 +0000)
writeback=True values are written to the backing store when assigned to
the shelf.  Add test to confirm that this happens.  Doc patch and added
test by Robert Lehmann.  I also fixed the cross references to the sync
and close methods.

Doc/library/shelve.rst
Lib/test/test_shelve.py
Misc/ACKS

index 5d82dc42d54912b02e2cd53a507df3d895f91bc1..c0bcb80f19090a1257ee9adfbb6c2b241ebf338a 100644 (file)
@@ -30,14 +30,15 @@ lots of shared  sub-objects.  The keys are ordinary strings.
 
    Because of Python semantics, a shelf cannot know when a mutable
    persistent-dictionary entry is modified.  By default modified objects are
-   written only when assigned to the shelf (see :ref:`shelve-example`).  If the
-   optional *writeback* parameter is set to *True*, all entries accessed are
-   cached in memory, and written back on :meth:`sync` and :meth:`close`; this
-   can make it handier to mutate mutable entries in the persistent dictionary,
-   but, if many entries are accessed, it can consume vast amounts of memory for
-   the cache, and it can make the close operation very slow since all accessed
-   entries are written back (there is no way to determine which accessed entries
-   are mutable, nor which ones were actually mutated).
+   written *only* when assigned to the shelf (see :ref:`shelve-example`).  If the
+   optional *writeback* parameter is set to *True*, all entries accessed are also
+   cached in memory, and written back on :meth:`~Shelf.sync` and
+   :meth:`~Shelf.close`; this can make it handier to mutate mutable entries in
+   the persistent dictionary, but, if many entries are accessed, it can consume
+   vast amounts of memory for the cache, and it can make the close operation
+   very slow since all accessed entries are written back (there is no way to
+   determine which accessed entries are mutable, nor which ones were actually
+   mutated).
 
    .. note::
 
index 3b20281a02b9b9e660889287607b35f64469d95d..df56625a599843b0885c8ff45b19bf144a35b733 100644 (file)
@@ -90,6 +90,17 @@ class TestCase(unittest.TestCase):
         self.assertEqual(len(d1), 1)
         self.assertEqual(len(d2), 1)
 
+    def test_writeback_also_writes_immediately(self):
+        # Issue 5754
+        d = {}
+        s = shelve.Shelf(d, writeback=True)
+        s['key'] = [1]
+        p1 = d['key']  # Will give a KeyError if backing store not updated
+        s['key'].append(2)
+        s.close()
+        p2 = d['key']
+        self.assertNotEqual(p1, p2)  # Write creates new object in store
+
 
 from test import mapping_tests
 
index 0ce586eb4e920dd5aed90cdd3d99c17aa4991579..b389f775d9f6b825961f19cb7491ff79a5b647b0 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -444,6 +444,7 @@ Luc Lefebvre
 Vincent Legoll
 Kip Lehman
 Joerg Lehmann
+Robert Lehmann
 Luke Kenneth Casson Leighton
 Marc-Andre Lemburg
 John Lenton