[Python-ideas] f-string "debug" conversion
Anders Hovmöller
boxed at killingar.net
Wed Oct 3 04:02:30 EDT 2018
>> Here’s the idea: for f-strings, we add a !d conversion operator, which
>> is superficially similar to !s, !r, and !a. The meaning of !d is:
>> produce the text of the expression (not its value!),
>
> I SO WANT THIS AS A GENERAL FEATURE, not just for f-strings, it hurts.
>
> Actually what I want is an executable object (a function?) which has the
> AST and text of the expression attached. If putting this into f-strings
> is a first step towards getting this thunk-like thing, then I don't
> need to read any further, I'm +10000 :-)
Well... this is a trivial expansion of the keyword argument short form proposal you were very strongly opposed ^_-
So, I suggested `foo(=a)` as short form for `foo(a=a)`, but if we interpret it instead as `foo(=a)` -> `foo(**{'a': a}`, which is really the same thing for most purposes, then we could trivially get `foo(=1+3*bar)` -> 'foo(**{'1+3*bar': 1+3*bar})'
I'm fine with this proposal. And thanks Chris for the idea!
/ Anders
More information about the Python-ideas
mailing list