New submission from Mark Dickinson <dicki...@gmail.com>: 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 ---------- components: Interpreter Core messages: 103330 nosy: mark.dickinson priority: normal severity: normal stage: unit test needed status: open title: dict constructor allows invalid identifiers in **kwargs type: behavior versions: Python 3.2, Python 3.3 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue8419> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com