[issue5754] Shelve module writeback parameter does not act as advertised

2010-02-10 Thread R. David Murray

R. David Murray  added the comment:

Thanks for the patch.  I applied the doc patch and a slightly simplified 
version of the test in r78141 (we tend to just let errors bubble up rather than 
code explicit Fails, since as often as not if you provide a specific message it 
turns out to be wrong when something breaks the test).
I'll merge the change to the other branches as well.

--
assignee: aleax -> r.david.murray
nosy: +r.david.murray
priority:  -> normal
resolution:  -> accepted
stage: test needed -> committed/rejected
status: open -> closed
versions: +Python 2.7, Python 3.1, Python 3.2

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5754] Shelve module writeback parameter does not act as advertised

2009-09-17 Thread Robert Lehmann

Robert Lehmann  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 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5754] Shelve module writeback parameter does not act as advertised

2009-04-21 Thread Daniel Diniz

Changes by Daniel Diniz :


--
keywords: +easy
stage:  -> test needed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5754] Shelve module writeback parameter does not act as advertised

2009-04-14 Thread Raymond Hettinger

Changes by Raymond Hettinger :


--
assignee:  -> aleax
nosy: +aleax

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue5754] Shelve module writeback parameter does not act as advertised

2009-04-14 Thread Jorge Herskovic

New submission from Jorge Herskovic :

The shelve module documentation states that "by default, mutations to
persistent-dictionary mutable entries are not automatically written
back. If the optional writeback parameter is set to True, all entries
accessed are cached in memory, and written back at close time..."
however the implementation's __setitem__ is the following:
def __setitem__(self, key, value):
if self.writeback:
self.cache[key] = value
f = StringIO()
p = Pickler(f, self._protocol)
p.dump(value)
self.dict[key] = f.getvalue()

which maintains the cache correctly but writes back to the disk on every
operation, violating the writeback documentation. Changing it to 
def __setitem__(self, key, value):
if self.writeback:
self.cache[key] = value
else:
f = StringIO()
p = Pickler(f, self._protocol)
p.dump(value)
self.dict[key] = f.getvalue()

seems to match the documentation's intent.

(First report, sorry for any formatting/style issues!)

--
components: Extension Modules
messages: 85971
nosy: jherskovic
severity: normal
status: open
title: Shelve module writeback parameter does not act as advertised
type: behavior
versions: Python 2.6

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com