On Thu, Sep 17, 2020 at 2:31 PM Dennis Sweeney <sweeney.dennis650@gmail.com> wrote:
I was definitely not proposing "spooky action at a distance". My proposal is to existing f-strings as the `__setattr__` protocol is to the `__getattr__` protocol. The template would only ever be hard-coded inline during the f-string assignment. This is the same restriction that existing f-strings have. I am suggesting a syntactic construct where f-strings can be assignment targets, not suggesting to keep track of which strings were f-strings or overriding assignment or something silly like that.

Just to be clear, I hate the idea.

But I get that you are talking about the expansions in an f-string as a weird kind of assignment target.  There are so very many ways this can go wrong that would be a nightmare to debug... and at best, it's very difficult to read.

Let's go through a few:

 >>> f"It is {hh}:{mm} {am_or_pm}" = "It is 11:45 PM"

OK, this is a weird way to call a parser on the RHS.  But if it parses, it's like:

    hh, mm, am_or_pm = "11", "45", "PM"

Let's try some others:

>>> my_string = "It might be 11:45 PM"
>>> # ... many lines later ...
>>> f"It is {hh}:{mm} {am_or_pm}" = my_string

What are hh, mm, and am_or_pm now?  Do we raise an exception?  Do we run the line having no real idea whether they have been assigned at all? How do we even check whether an assignment took place?

>>> f"It is {hh}:{mm}!" = "It is 11:45 PM"

Does this work left-to-right? Are hh and mm assigned values, but am_or_pm remains unassigned?

>>> f"It is {hh}:{mm} {am_or_pm} right now" = "It is 11:45 PM"
 
Is this a match? Do we only care about the prefix, or does the whole string need to match the inflexible pattern? Obviously, why not use regexen where we can be explicit about such things?

>>> f"It is {hh}:{mm} {am_or_pm}" = "It is 11:45 PM right now"

Same questions as last, but kinda flipped around? There is no easy intution here, and every behavior will be surprising to most users.

 >>> f"It is {hh()}:{mm()} {am_or_pm()}" = "It is 11:45 PM"

That's a perfectly valid f-string on the LHS. What would you imagine would happen here? If the answer is "raise an exception" then your proposal is actually that some tiny fraction of f-strings could actually be used this way.  That doesn't per se mean the syntax is bad (although it is), but it means that the "symmetries" you hope for between `=` and `==` will hold only for very special cases of f-strings.