Non-identifiers in dictionary keys for **expression syntax
Matthew Gilson
m.gilson1 at gmail.com
Thu May 23 14:52:07 EDT 2013
This is a question regarding the documentation around dictionary
unpacking. The documentation for the call syntax
(http://docs.python.org/3/reference/expressions.html#grammar-token-call)
says:
"If the syntax **expression appears in the function call, expression
must evaluate to a mapping, the contents of which are treated as
additional keyword arguments."
That's fine, but what is a keyword argument? According to the glossary
(http://docs.python.org/3.3/glossary.html):
/"keyword argument/: an argument preceded by an identifier (e.g. name=)
in a function call or passed as a value in a dictionary preceded by **."
As far as I'm concerned, this leads to some ambiguity in whether the
keys of the mapping need to be valid identifiers or not.
Using Cpython, we can do the following:
def func(**kwargs):
print kwargs
d = {'foo bar baz':3}
So that might lead us to believe that the keys of the mapping do not
need to be valid identifiers. However, the previous function does not
work with the following dictionary:
d = {1:3}
because not all the keys are strings. Is there a way to petition to get
this more rigorously defined?
Thanks,
~Matt
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20130523/a31fb8c5/attachment.html>
More information about the Python-list
mailing list