PEP 750: Tag Strings For Writing Domain-Specific Languages

I’m a fan of the feature in general but find myself agreeing with @erictraut:

My understanding is that JavaScript’s tagged templates (mentioned in the PEP) perform eager evaluation. Personally, I’d like to see stronger motivation and examples for lazy evaluation given the drawbacks mentioned above. I think it will be a source of confusion for users especially because f-strings themselves don’t use these semantics.

I would also prefer this. I find it more intuitive and strictly more flexible, since you can always wrap in a lambda (but not the other way around). If you actually want values to be evaluated lazily, it seems right to me that you should be opting into that.

I would argue that explicitly requiring users to write lambda: would be both more explicit about the behavior and more intuitive to users given that f-strings are eagerly evaluated, thus reducing the burden to carefully read the documentation.

11 Likes