[Python-Dev] Arbitrary non-identifier string keys when using **kwargs
Terry Reedy
tjreedy at udel.edu
Sun Oct 7 18:44:54 EDT 2018
On 10/7/2018 1:34 PM, Chris Barker via Python-Dev wrote:
> On Fri, Oct 5, 2018 at 3:01 PM Brett Cannon <brett at python.org
> <mailto:brett at python.org>> wrote:
>
> I'm also fine with saying that keys in **kwargs that are not proper
> identifiers is an implementation detail.
>
>
> It's not just **kwargs -- you can also use arbitrary names with
> setattr() / getattr() :
>
> In [6]: setattr(foo, "4 not an identifier", "this works")
>
> In [7]: getattr(foo, "4 not an identifier")
> Out[7]: 'this works'
When this behavior of set/getattr was discussed a decade or so ago,
Guido said not to disable it, but I believe he said it should not be
considered a language feature. There are other situations where CPython
is 'looser' than the spec.
--
Terry Jan Reedy
More information about the Python-Dev
mailing list