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.

Existing f-strings do not aim to replace str.format in situations where the 
format string is re-used.
Likewise, the proposal would not aim to replace regular expression in 
situations where the pattern is re-used.

The change would amount a syntax change for assignments: whenever an f-string 
is on the LHS of an assignment, the interpreter would do a parsing operation, 
and there would be no change to code where the f-string is in any other 
situation. This is again analogous to the behavior of `__getattr__` and 
`__setattr__`.

For example, 

    f"""<a href="{url}">{text}</a>""" = html

Would be roughly equivalent to

    url, text = re.fullmatch(r"""<a href="(.*)">(.*)</a>""", html).groups()

The LHS is never evaluated, it's only assigned to.
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/5R72K64RQUDJAZJOFUFDX6JQRSNLY5M2/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to