[Python-ideas] f-string "debug" conversion
Anders Hovmöller
boxed at killingar.net
Wed Oct 3 04:48:31 EDT 2018
>> 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".
That was what it was. That was not intended to be about magic, that was the normal case where you didn't want the magic. I think you might be taking a habit of interpreting my mails in the least flattering way due to our previous disagreements. I hope we can put this behind us going forward.
> Things which contain compiler magic should look special, not like
> ordinary function calls.
Good. I agree :P
>>> 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 don't really think accidents of implementation are different from hard requirements in Python, as it applies to alternative implementations. In practice if it deviates from CPython then it's broken. There is no language spec, there is only CPython. This has been the experience and approach of PyPy as far as I've understood it after having followed their blog over the years.
/ Anders
More information about the Python-ideas
mailing list