osdir.com

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


My feeling is that limiting it to strings is fine, but checking those
strings for resembling identifiers is pointless and wasteful.

On Tue, Oct 9, 2018 at 9:40 AM Jeff Hardy <jdhardy at gmail.com> wrote:

> 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
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> https://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe:
> https://mail.python.org/mailman/options/python-dev/guido%40python.org
>
-- 
--Guido (mobile)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20181009/d39ba8a1/attachment.html>