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

Anders Hovmöller boxed at killingar.net
Wed Oct 3 00:57:19 EDT 2018


>> debug(=value, =another)
> 
> What if it's not a simple name, though? The OP gave this (somewhat
> simplistic, but indicative) example:
> 
> print(f'next: {value+1!d}')

debug(next=value+1)

Still shorter than the proposed syntax and much more readable. If you do this a lot you’d probably call the function just “d” too. 

> 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.

> even though it does work in current versions of CPython. So even if
> your "=value" syntax did permit it, I wouldn't want to guarantee that
> in the language.

Well I haven’t suggested my syntax would support that. But yea, I realize I was pretty vague in my last email!

> (Side point: Please watch your mailer. The debug() function above has
> smart quotes in it, which means it can't be copied and pasted into the
> interpreter. Not a big problem with trivially-simple functions, but if
> it's something larger, it's annoying to have to track down
> "SyntaxError: invalid character in identifier" to figure out why it's
> not doing what you think it is.)

Huh. I’ll look into it. Thanks for the heads up. 

/ Anders


More information about the Python-ideas mailing list