This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: fix UserDict.get, setdefault, update
Type: Stage:
Components: Library (Lib) Versions:
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: ping Nosy List: gvanrossum, loewis, ping
Priority: low Keywords: patch

Created on 2001-04-02 17:18 by ping, last changed 2022-04-10 16:03 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
UserDict.patch ping, 2001-04-02 17:18
Messages (5)
msg36252 - (view) Author: Ka-Ping Yee (ping) * (Python committer) Date: 2001-04-02 17:18
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.
msg36253 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2001-04-10 21:17
Logged In: YES 
user_id=6380

Let's not fix this in 2.1.
msg36254 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2001-06-07 05:25
Logged In: YES 
user_id=21627

I recommend to approve this patch.
msg36255 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2001-06-07 15:10
Logged In: YES 
user_id=6380

Approved.  Check it in already!
msg36256 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2001-06-18 01:10
Logged In: YES 
user_id=21627

Committed as UserDict 1.14.
History
Date User Action Args
2022-04-10 16:03:55adminsetgithub: 34267
2001-04-02 17:18:02pingcreate