[Patches] [ python-Patches-917095 ] dict type concat function
SourceForge.net
noreply at sourceforge.net
Tue Mar 16 06:08:10 EST 2004
Patches item #917095, was opened at 2004-03-16 00:33
Message generated for change (Comment added) made by rhettinger
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=917095&group_id=5470
Category: Core (C code)
Group: Python 2.4
Status: Open
Resolution: None
Priority: 5
Submitted By: troy melhase (troy_melhase)
Assigned to: Nobody/Anonymous (nobody)
Summary: dict type concat function
Initial Comment:
Adds a function to dictobject.c that allows python
expressions like:
>>> d = {2:3}
>>> d += {4:5}
>>> d
{2: 3, 4: 5}
and like:
>>> d = {2:3}
>>> e = d + {6:7}
>>> e
{2: 3, 6: 7}
A few points:
* I don't know much C, and this patch is probably
implemented much more appropriately by someone who
does
* I don't know if there's a good reason that the dict
type doesn't already supply this; if that's the case,
I'd be interested to know why not
* Lib/test/test_builtin.py fails (as it should) after
applying this patch
Please advise, and thanks!
----------------------------------------------------------------------
>Comment By: Raymond Hettinger (rhettinger)
Date: 2004-03-16 06:08
Message:
Logged In: YES
user_id=80475
I recommend against this for several reasons:
1) adds new syntax but not new functionality
2) concept doesn't usefully extend to - and *
3) writing d.update(x) is clearer and more flexible -- in
Py2.4, update() can take the same arguments as dict()
4) no use cases showing the + operator to be more
expressive
5) possibly confusing given the | operator is used for sets
6) {1:4}+{1:7} is not commutative and unlike list addition,
there is no underlying order that makes the non-
commutativity obvious. IOW, the operator may introduce a
new class of hard to find bugs.
If for some reason this gets approved, please assign back to
me for implementation, documentation, and unittests.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=917095&group_id=5470
More information about the Patches
mailing list