Custom Strings: h'.....'

Last summer I did some exploration with @guido of a rough analogue to JavaScript’s tagged templates for Python in a personal repo, along with some related ideas like fl-strings and Quote objects. Unfortunately I got very busy later in the summer, amplified by the pandemic, so I didn’t have time/energy to look into this topic further.

This exploration can be taken in several directions, and it’s likely worth revisiting. Some points to consider:

  • As I understand it, JS does implement tagged templates and corresponding tag functions using static analysis. This would not be the way we would want to do it in Python! One should be able to define/import/manipulate/mock such tag functions as usual.
  • On the other hand, the use of variables in such strings should not require the use of sys._getframe (as we see with say flufl.i18n). Avoiding this usage was a good design decision for f-strings. Also, lexical scope is better :slight_smile: .
  • Minimizing overhead of the quoting is important. f-strings are popular in part because they are fast, not just because they are also easy to use.

Personally this idea is something I do again have time to look into.

1 Like