[Python-ideas] f-string "debug" conversion

Chris Angelico rosuav at gmail.com
Wed Oct 3 04:29:32 EDT 2018


On Wed, Oct 3, 2018 at 6:06 PM Steven D'Aprano <steve at pearwood.info> wrote:
>
> On Wed, Oct 03, 2018 at 06:57:19AM +0200, Anders Hovmöller wrote:
>
> > debug(next=value+1)
> >
> > Still shorter than the proposed syntax
>
> Are we trying to emulate Perl now? *wink*
>
>
> > and much more readable.
>
> So you say.
>
> To me that looks like a regular function call, which calls an ordinary
> function "debug" and takes a simple keyword argument next with value
> "value+1".
>
> Things which contain compiler magic should look special, not like
> ordinary function calls.
>
>
> > > AIUI, keyword arguments are all supposed to be legal names/atoms, so
> > > you aren't supposed to do something like this:
> > >
> > > debug(**{"value+1":value+1})
> >
> > Really? That seems pretty weird to me. I’ve used that type of thing in
> > production code from time to time.
>
> The fact that this works is, I think, an accident of implementation:
>
> py> def spam(**kw):
> ...     print(kw)
> ...
> py> spam(**{"value+1": 42})
> {'value+1': 42}
>
> rather than a guaranteed language feature. I can't find any relevent
> documentation on it, but I'd be very wary about relying on it.
>
> (To be honest, I expected it to fail until I tried it.)

I can't find any documentation either, but ISTR it's been stated as a
CPython implementation detail, not a language feature. Other Pythons
are entirely free to reject this.

ChrisA


More information about the Python-ideas mailing list