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 for bug 639806: default for dict.pop
Type: Stage:
Components: Interpreter Core Versions: Python 2.3
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: gvanrossum, mbrierst, rhettinger, tim.peters
Priority: normal Keywords: patch

Created on 2003-02-26 16:51 by mbrierst, last changed 2022-04-10 16:07 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
patchpop mbrierst, 2003-02-26 16:52
patchpop2 mbrierst, 2003-03-04 17:19
patchpop3 mbrierst, 2003-03-04 18:55
Messages (11)
msg42902 - (view) Author: Michael Stone (mbrierst) Date: 2003-02-26 16:51
This patch adds an optional default value to dict.pop,
so that it parallels dict.get, see discussion in bug
639806.

If no default is given, the old behavior still exists,
so backwards compatibility is no problem.
The new pop must use METH_VARARGS
and PyArg_UnpackTuple, somewhat effecting
efficiency.

If this is considered desirable, I could also
provide the same behavior for list.pop.
msg42903 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2003-03-01 01:30
Logged In: YES 
user_id=80475

The patch looks fine.  Assigning to Guido for 
pronouncement.

Guido, the patch adds optional get() like functionality for 
dict.pop().  The nearest parallel is the default argument for 
getattr(obj, attr, [default]).  On the plus side, it makes pop 
easier to use and more flexible.  On the minus side, it adds 
more complexity to the mapping interface and it slows 
down the normal case for d.pop(k).

If it is accepted the poster should add test cases, a NEWS 
item, doc updates, and parallel changes to 
UserDict.UserDict and UserDict.DictMixin.  Then, re-assign 
to me and I'll check it all and apply it.

msg42904 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2003-03-01 02:59
Logged In: YES 
user_id=6380

Alex Martelli's argument convinced me, I'm +0.5 on the
feature. The 0.5 is because it's definitely feature bloat.
Given how few use cases there are for dict.pop() in the
first place, I'm not worried about the minor slowdown due to
extra argument parsing.
msg42905 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2003-03-02 02:40
Logged In: YES 
user_id=31435

dicts have a .pop() method?  Heh.  I must have slept 
through that one <wink>.
msg42906 - (view) Author: Michael Stone (mbrierst) Date: 2003-03-03 19:59
Logged In: YES 
user_id=670441

Should I make a new NEWS item, or should
I modify the existing NEWS item about dict.pop?

And should I make a new whatsnew23 item or
modify the existing one?

I'm guessing a new NEWS item and a modified
whatsnew item, but I'll post a patch when you tell me.
msg42907 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2003-03-04 04:26
Logged In: YES 
user_id=80475

For NEWS, add a new entry (so that it documents a 
difference from Py2.3a2).

For whatsnew23, modify the existing entry (since it is a 
delta from Py2.3).
msg42908 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2003-03-04 15:19
Logged In: YES 
user_id=6380

You don't need to update whatsnew23.tex; its editor prefers
to do this himself.
msg42909 - (view) Author: Michael Stone (mbrierst) Date: 2003-03-04 17:19
Logged In: YES 
user_id=670441

Okay, here's patchpop2 with the diff'ed dictobject,
UserDict, test_types, test_userdict, NEWS, and
Doc/lib/libstdtypes.  whew.

Let me know if you need any changes.
The change to DictMixin seems a bit
clumsy, but I liked it better than other things
I came up with.
msg42910 - (view) Author: Michael Stone (mbrierst) Date: 2003-03-04 18:55
Logged In: YES 
user_id=670441

argh... I put the NEWS item in the wrong place.
Ignore patchpop2(I can't delete it), look at patchpop3.
msg42911 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2003-03-07 00:08
Logged In: YES 
user_id=80475

Misc/NEWS 1.69
Objects/dictobject.c 2.141
Doc/lib/libstdtypes.tex 1.120
Lib/UserDict.py 1.24
Lib/test/test_types.py 1.47
Lib/test/test_userdict.py 1.13
msg42912 - (view) Author: Michael Stone (mbrierst) Date: 2003-03-07 04:31
Logged In: YES 
user_id=670441

Thanks for fixing up my UserDict.DictMixin patch.
Much nicer.
History
Date User Action Args
2022-04-10 16:07:09adminsetgithub: 38060
2003-02-26 16:51:07mbrierstcreate