![](https://secure.gravatar.com/avatar/2828041405aa313004b6549acf918228.jpg?s=120&d=mm&r=g)
On 9/17/2020 11:38 AM, Eric V. Smith wrote:
In general, there's no way to start with a format specifier string and from it get the type of the object that it should be applied to. For example, any string without %'s is a valid datetime format specifier (of dubious value, but such is life). Perhaps a better example is decimal vs. float. What if I want %.2f to return a decimal? Would that just not be possible?
So I think you'd have to limit this to a small set of built-in types.
In general, I think overloading f-strings as assignment targets would be confusing. But I've been wrong before.
Also, it only works with literals. I can easily see wanting to build up the scanf-like string programatically. So that puts me at -1. f-strings only being literals is to avoid code injection. There's no such requirement with a scanf-like string that basically describes a regex and some assignment targets. Eric