[Python-Dev] Arbitrary non-identifier string keys when using **kwargs

Jeff Hardy jdhardy at gmail.com
Tue Oct 9 12:37:48 EDT 2018


On Sun, Oct 7, 2018 at 3:45 PM Terry Reedy <tjreedy at udel.edu> wrote:
>
> 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.

>From an alternative implementation point of view, CPython's behaviour
*is* the spec. Practicality beats purity and all that.

- Jeff


More information about the Python-Dev mailing list