[Python-bugs-list] [ python-Feature Requests-520382 ] Update Shelve to be more dictionary like

noreply@sourceforge.net noreply@sourceforge.net
Thu, 14 Nov 2002 08:51:12 -0800


Feature Requests item #520382, was opened at 2002-02-20 03:39
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=520382&group_id=5470

Category: Python Library
Group: None
Status: Open
>Resolution: Accepted
Priority: 5
Submitted By: Raymond Hettinger (rhettinger)
Assigned to: Raymond Hettinger (rhettinger)
Summary: Update Shelve to be more dictionary like

Initial Comment:
It's great to be able to add persistence by replacing 
a dictionary declaration with a shelf; however, it is 
not as substitutable as it could be.

Most importantly, we should add __iter__ so that
'for k in d' works for shelves as well as dictionaries.

Also 
add  .items .iteritems .iterkeys .itervalues .popitem .
setdefault .update and .values

These methods could be added to increase 
substitutability without affecting existing code.

----------------------------------------------------------------------

>Comment By: Tim Peters (tim_one)
Date: 2002-11-14 11:51

Message:
Logged In: YES 
user_id=31435

Marked Accepted since Guido approved.

----------------------------------------------------------------------

Comment By: Guido van Rossum (gvanrossum)
Date: 2002-11-14 07:58

Message:
Logged In: YES 
user_id=6380

Please go ahead. I'll apply my minor quibbles once it's in
CVS. :-)

----------------------------------------------------------------------

Comment By: Raymond Hettinger (rhettinger)
Date: 2002-11-14 01:44

Message:
Logged In: YES 
user_id=80475

Yes.  DictMixin moved to UserDict.
Yes.  has_key() now uses try/except (much better).
Yes.  __contains__ aliased to has_key
Added news item and docs.
See new patch below.

If the design is acceptable, I'll move on to writing the
unittests.

----------------------------------------------------------------------

Comment By: Guido van Rossum (gvanrossum)
Date: 2002-11-13 23:12

Message:
Logged In: YES 
user_id=6380

What's py-dev? I don't recall a discussion on DictMixin on
python-dev, so is it something different, maybe IRC?

Maybe DIctMixin can live in UserDict?

has_key() should not call keys(); it should try self[key]
and catch the KeyError.

__contains__ should just be an alias for has_key rather than
a wrapper.

But those are all details; I like the ideas here.

----------------------------------------------------------------------

Comment By: Raymond Hettinger (rhettinger)
Date: 2002-11-13 21:29

Message:
Logged In: YES 
user_id=80475

Here is a concept sketch patch for expanding the shelve 
interface.  The goal is to make it is easier to add 
persistence when an application was already developed 
using dictionaries as a base.

On a separate note, DictMixin is offered as a stand-alone 
class to make it easier to create classes with a full 
dictionary interface.  On py-dev, we concluded that 
DictMixin did not warrant its own module, so this would be 
a good place to expose the mixin class as an experimental 
feature while taking care of shelve at the same time.

If the concept sketch appeals to you, I'll add docs, 
unittests, and a news item.  DictMixin would be listed as 
experimental and potentially would not be visible in future 
versions of Python.



----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=355470&aid=520382&group_id=5470