[Python-Dev] The interpreter accepts f(**{'5':'foo'}); is this intentional?

Michael Haggerty mhagger at alum.mit.edu
Thu Feb 5 09:03:01 CET 2009


I can't find documentation about whether there are constraints imposed
on the keys in the map passed to a function via **, as in f(**d).

According to

    http://docs.python.org/reference/expressions.html#id9

, d must be a mapping.

test_extcall.py implies that the keys of this map must be strings in the
following test:

    >>> f(**{1:2})
    Traceback (most recent call last):
      ...
    TypeError: f() keywords must be strings

But must the keys be valid python identifiers?

In particular, the following is allows by the Python 2.5.2 and the
Jython 2.2.1 interpreters:

    >>> f(**{'1':2})
    {'1': 2}

Is this behavior required somewhere by the Python language spec, or is
it an error that just doesn't happen to be checked, or is it
intentionally undefined whether this is allowed?

Michael


More information about the Python-Dev mailing list