[Patches] [ python-Patches-642500 ] Allow keyword args in dict() constructor

noreply@sourceforge.net noreply@sourceforge.net
Fri, 22 Nov 2002 17:47:48 -0800


Patches item #642500, was opened at 2002-11-22 15:11
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=642500&group_id=5470

Category: Core (C code)
Group: Python 2.3
Status: Open
>Resolution: Accepted
Priority: 5
Submitted By: Just van Rossum (jvr)
>Assigned to: Just van Rossum (jvr)
Summary: Allow keyword args in dict() constructor

Initial Comment:
I sometimes use an idiom like

  def dictfromkeywords(**kwargs):
      return kwargs

  d = dictfromkeywords(
          akey = 12,
          anotherkey = "foo",
          ...etc.
  )

to conveniently build dicts with literal keys. This
patch adds this behavior to the dict constructor so one
can write:

  dict(one=1, two=2)

The patch patches Doc/lib/libfuncs.text,
Objects/dictobject.c, Lib/test/test_descr.py and Misc/NEWS

The dictobject.c patch contains an XXX comment about
something I'm not 100% sure about. Please review.

Thanks to Raymond H. for earlier comments.

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

>Comment By: Raymond Hettinger (rhettinger)
Date: 2002-11-22 20:47

Message:
Logged In: YES 
user_id=80475

Looks good.
Passes review.
Marking as accepted.

Here are some nits before committing:

-- Replace 'elimated' with 'eliminated' in the NEWS entry.

-- I rethought the wording in dictobject.c.  Consider 
replacing "name/value pairs" with "name=value pairs".

-- In libfuncs.tex, replace "Else" with "Otherwise".

-- The tex markup is almost fine, but add a blank line to 
trigger a paragraph break between the paragraph ending 
with "dictionary." and the one starting with "If keyword 
arguments".

-- The {"two":3} example has an oxymoron quality that 
unnecessarily distracts from the message.  Replace it with 
something less confusing and suggesting a legitimate use, 
such as:  {"red":1,"blue:2}.

-- The test suite looks perfect to the eye.  Consider running 
a whitespace normalization just to be sure.


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

Comment By: Just van Rossum (jvr)
Date: 2002-11-22 15:29

Message:
Logged In: YES 
user_id=92689

Oops, the doctobject.c *doesn't* contain an XXX comment, I
was thinking of an earlier version of the patch. As far as I
can see the patch is fine as is (although Fred may want to
double check the libfuncs.tex patch).

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

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