[Python-ideas] Dictionary initialization to capture syntax and value (was Re: Debugging: some problems and possible solutions)

Chris Angelico rosuav at gmail.com
Wed Oct 3 14:17:41 EDT 2018

On Thu, Oct 4, 2018 at 4:12 AM Jonathan Fine <jfine2358 at gmail.com> wrote:
> Anders Hovmöller suggested
> > Short form of keyword arguments where
> > foo(=a, =1+bar)
> > Is expanded at compile time to
> > foo(**{'a': a, '1+bar': 1+bar})
> Chris Angelico wrote:
> > That is not guaranteed to work. In another thread it was pointed out
> > that this is merely a CPython implementation detail, NOT a language
> > feature.
> Here's a variant of Anders' suggestion.  First, here's a dict literal
>     {'a':1, 'b': 2, 'c':3}
> and here's another way to write an equivalent dict
>     dict(a=1, b=2, c=3)
> So how about extending Python so that, for example,
>     {=(1 + bar), }
> is equivalent to
>     {'1 + bar': 1 + bar, }
> The basic idea is Anders's, recast to avoid Chris's problem.
> Anders: Are you willing to accept this change, if need be?
> Chris: Please speak up, if you think this may depend on CPython.

And then you just pass the dictionary as-is? That would be plausible,
but I'm not a big fan of the syntax. Feels very clunky and forced.

Spun off as a new thread because this isn't really specific to debugging.


More information about the Python-ideas mailing list