[Patches] [ python-Patches-693753 ] fix for bug 639806: default for dict.pop

SourceForge.net noreply@sourceforge.net
Mon, 03 Mar 2003 11:59:54 -0800


Patches item #693753, was opened at 2003-02-26 16:51
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=693753&group_id=5470

Category: Core (C code)
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Michael Stone (mbrierst)
Assigned to: Raymond Hettinger (rhettinger)
Summary: fix for bug 639806: default for dict.pop

Initial Comment:
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.

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

>Comment By: Michael Stone (mbrierst)
Date: 2003-03-03 19:59

Message:
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.

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

Comment By: Tim Peters (tim_one)
Date: 2003-03-02 02:40

Message:
Logged In: YES 
user_id=31435

dicts have a .pop() method?  Heh.  I must have slept 
through that one <wink>.

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

Comment By: Guido van Rossum (gvanrossum)
Date: 2003-03-01 02:59

Message:
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.

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

Comment By: Raymond Hettinger (rhettinger)
Date: 2003-03-01 01:30

Message:
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.



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

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