Robert Lehmann <lehman...@gmail.com> added the comment: I think you're misquoting Python's shelve module documentation in your first sentence. The documentation says: "By default modified objects are written only when assigned to the shelf [...]. If the optional writeback parameter is set to True, all entries accessed are cached in memory, and written back at close time [...]."
The emphasis should be on the word "only:" it does *always* write to the database when assigned to the shelf but, iff writeback=True, *also* to the cache. Also consider the consequences of *only* caching keys: (a) __contains__ and has_key have to consult the dict and the cache for membership tests. (b) keys and __len__ need to compute a union of both sources. (c) __delitem__ is no longer guaranteed to fail on the cache if it failed for the database. I admit the docs could spell this out more clearly. I attached a patch ensuring the behaviour I described in a test and updating the docs. (Note: shelve is no extension module -- it's part of the stdlib. Patch applies to 3.x as well.) ---------- components: +Library (Lib) -Extension Modules keywords: +patch nosy: +lehmannro Added file: http://bugs.python.org/file14909/issue5754.patch _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue5754> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com