[Patches] [ python-Patches-413171 ] fix UserDict.get, setdefault, update

noreply@sourceforge.net noreply@sourceforge.net
Thu, 10 May 2001 14:17:14 -0700


Patches item #413171, was updated on 2001-04-02 10:18
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=413171&group_id=5470

Category: library
Group: None
Status: Open
Resolution: Postponed
Priority: 4
Submitted By: Ka-Ping Yee (ping)
>Assigned to: Ka-Ping Yee (ping)
Summary: fix UserDict.get, setdefault, update

Initial Comment:
The methods 'get', 'setdefault', and 'update'
on a dictionary are usually implemented (and
thought of) in terms of the lower-level methods
has_key, __getitem__, and __setitem__.  The
current implementation of UserDict relays a
call to e.g. x.get() to x.data.get(), which
behaves inconsistently if __getitem__ has been
implemented on x.

One particular big place where this turns up is cgi.
If you get a dict = cgi.SvFormContentDict(), then
dict.get('key') will return a *list* even though
dict['key'] returns a single item!

To make UserDict behave consistently, this patch
fixes get(), update(), and setdefault() to re-use
the other methods.  Then the only occurrence of
self.data[k] = v is in __setitem__, the only
occurrence of self.data[k] without assignment is
in __getitem__, etc.

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

Comment By: Guido van Rossum (gvanrossum)
Date: 2001-04-10 14:17

Message:
Logged In: YES 
user_id=6380

Let's not fix this in 2.1.

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

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=305470&aid=413171&group_id=5470