Issue 1600: jython dict() behaving differently from cpython's. (original) (raw)
Created on 2010-04-15.20:19:42 by draghuram, last changed 2010-04-16.15:23:57 by draghuram.
Messages
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/dicttest.py", line 4, in print dict(d, **d2) TypeError: type keywords must be strings
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 "", line 1, in TypeError: f() keywords must be strings dict(**{1: 3, 2: 7}) {1: 3, 2: 7}
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 http://code.djangoproject.com/ticket/13357.
I will patch Django 1.1 (which is the only one supported by DOJ) and see if that works ok.
Author: Raghuram Devarakonda (draghuram)
Date: 2010-04-16.13:21:14
On Fri, Apr 16, 2010 at 9:10 AM, Raghuram Devarakonda <report@bugs.jython.org> 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.
Author: Raghuram Devarakonda (draghuram)
Date: 2010-04-16.14:51:17
python-dev discussion about same topic: http://mail.python.org/pipermail/python-dev/2010-April/099427.html
Author: Nicholas Riley (nriley)
Date: 2010-04-16.14:55:08
A nice coincidence - thanks for the pointer.
Author: Raghuram Devarakonda (draghuram)
Date: 2010-04-16.15:23:56
Just for information, python bug opened to deprecate this behavior: http://bugs.python.org/issue8419
History
Date
User
Action
Args
2010-04-16 15:23:57
draghuram
set
messages: +
2010-04-16 14:55:09
nriley
set
status: open -> closed
resolution: wont fix
messages: +
2010-04-16 14:51:17
draghuram
set
messages: +
2010-04-16 13:21:14
draghuram
set
messages: +
2010-04-16 13:10:58
draghuram
set
messages: +
2010-04-15 23:06:25
nriley
set
nosy: + nriley
messages: +
2010-04-15 20:19:42
draghuram
create