Title: jython dict() behaving differently from cpython's.
Type: behaviour Severity: normal
Components: Core Versions: 2.5b1
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: draghuram, nriley
Priority: Keywords:

Created on 2010-04-15.20:19:42 by draghuram, last changed 2010-04-16.15:23:57 by draghuram.

msg5711 (view) Author: Raghuram Devarakonda (draghuram) Date: 2010-04-15.20:19:40
I have run into this while using Django on Jython (in particular,
admin's "formfield_overrides" feature)  and have isolated the problem
in a small test script:

d = {1:2, 3:4}
d2 = {5:6, 7:8}

print dict(d, **d2)

When run using python (starting from 2.4 and above), I get the result
"{1: 2, 3: 4, 5: 6, 7: 8}". How ever, when run using jython from
trunk, i get the following error:

Traceback (most recent call last):
 File "/tmp/", line 4, in <module>
   print dict(d, **d2)
TypeError: type keywords must be strings
msg5712 (view) Author: Nicholas Riley (nriley) Date: 2010-04-15.23:06:24
This seems like a really bizarre edge case, perhaps not worth supporting.  
I'd argue it is a bug that CPython lets you do this with dict(), as it's not supported for ordinary Python functions.

>>> def f(**y): print y
>>> f(x=3,y=7)
{'y': 7, 'x': 3}
>>> f(**{1: 3, 2: 7})
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: f() keywords must be strings
>>> dict(**{1: 3, 2: 7})
{1: 3, 2: 7}
msg5713 (view) Author: Raghuram Devarakonda (draghuram) Date: 2010-04-16.13:10:58
Talk about coincidence! I have checked the Django code on trunk and saw that the offending code fragment got fixed just today. Check

I will patch Django 1.1 (which is the only one supported by DOJ) and see if that works ok.
msg5714 (view) Author: Raghuram Devarakonda (draghuram) Date: 2010-04-16.13:21:14
On Fri, Apr 16, 2010 at 9:10 AM, Raghuram Devarakonda
<> wrote:

> I will patch Django 1.1 (which is the only one supported by DOJ) and see if that works ok.

With the patch, my original issue with DOJ is now gone. Just to note,
the above mentioned Django issue mentions that PyPy also restricts
dict() behaviour that works in CPython so may be, jython can skip
fixing the issue too.
msg5715 (view) Author: Raghuram Devarakonda (draghuram) Date: 2010-04-16.14:51:17
python-dev discussion about same topic:
msg5716 (view) Author: Nicholas Riley (nriley) Date: 2010-04-16.14:55:08
A nice coincidence - thanks for the pointer.
msg5717 (view) Author: Raghuram Devarakonda (draghuram) Date: 2010-04-16.15:23:56
Just for information, python bug opened to deprecate this behavior:
Date User Action Args
2010-04-16 15:23:57draghuramsetmessages: + msg5717
2010-04-16 14:55:09nrileysetstatus: open -> closed
resolution: wont fix
messages: + msg5716
2010-04-16 14:51:17draghuramsetmessages: + msg5715
2010-04-16 13:21:14draghuramsetmessages: + msg5714
2010-04-16 13:10:58draghuramsetmessages: + msg5713
2010-04-15 23:06:25nrileysetnosy: + nriley
messages: + msg5712
2010-04-15 20:19:42draghuramcreate