Hi Wolfram

You tried
>    def f(a):
> ..   print(a)
>    f(**{"a":2})
> 2
>    f(**{"a+1":2})
> Traceback (most recent call last):
>   File "python", line 1, in <module>
> TypeError: f() got an unexpected keyword argument 'a+1'

This is exactly what I would have expected. Please consider the following:

>>> def f(a): pass
>>> f(**dict(b=1))
TypeError: f() got an unexpected keyword argument 'b'

> Does CPython count as "other python implementation"?

Yes and No. Both are half correct. CPython is the reference
implementation. Please also consider

>>> def f(a, **kwargs): pass
>>> f(a=1, **{'a+1': 2})

>>> f(a=1, **{(0, 1): 2})
TypeError: f() keywords must be strings

So far as I know, that a keyword be a string is the only constraint,
at least in CPython. For example

>>> def f(a, **kwargs): pass
>>> f(a=1, **{'': 2})
>>> f(a=1, **{'def': 2})

So I think Anders proposal works in CPython. I think you forgot the
**kwargs in the parameters to f.

best regards

Jonathan
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to