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.

Author mark.dickinson
Recipients mark.dickinson
Date 2010-04-16.15:03:01
SpamBayes Score 4.3343107e-13
Marked as misclassified No
Message-id <1271430185.29.0.771672162256.issue8419@psf.upfronthosting.co.za>
In-reply-to
Content
In all versions of CPython right now, the following works.

>>> dict({1:2}, **{3:4})
{1: 2, 3: 4}

Other Python implementations raise TypeError for this;  CPython should probably do the same, beginning with deprecating this behaviour in Python 3.2 and removing it in 3.3.

From a python-dev posting[1] by Alex Gaynor:

"""
I ran into the follow behavior while making sure Django works
correctly on PyPy.  The following behavior was observed in all tested
versions of CPython (2.5, 3.1):

>>> def f(**kwargs):
...     print(kwargs)
...
>>> kwargs = {1: 3}
>>>
>>> dict({}, **kwargs)
{1: 3}
>>> f(**kwargs)
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
TypeError: f() keywords must be strings
>>>

This behavior seems pretty strange to me, indeed PyPy gives the
TypeError for both attempts.  I just wanted to confirm that it was in
fact intentional.
"""

Raghuram Devarakonda says (in the same python-dev thread):

"I ran into same issue with Django on Jython yesterday [1] since Jython
too gives TypeError for 'dict({}, **kwargs)'."

Guido, on the suggestion that both the CPython and PyPy behaviour be left as is, and that the behaviour be regarded as implementation defined:

"That is just going to cause some programs to have a portability
surprise. I think one or the other should be fixed. I am fine with declaring dict({}, **{1:3}) illegal, since after all it is abuse of the ** mechanism. We should deprecate it in at least one version though."


[1] http://mail.python.org/pipermail/python-dev/2010-April/099427.html
History
Date User Action Args
2010-04-16 15:03:05mark.dickinsonsetrecipients: + mark.dickinson
2010-04-16 15:03:05mark.dickinsonsetmessageid: <1271430185.29.0.771672162256.issue8419@psf.upfronthosting.co.za>
2010-04-16 15:03:03mark.dickinsonlinkissue8419 messages
2010-04-16 15:03:01mark.dickinsoncreate