Currently:
>>> a = 1
>>> t'{a!something}'
SyntaxError: t-string: invalid conversion character 'something': expected 's', 'r', or 'a'
I propose relaxing this restriction and allowing any valid id. I.e. [a-zA-Z_][a-zA-Z0-9_]*.
Why this might be a good idea (besides the use cases):
- If one wants to have this restriction, adding it is trivial:
assert conversion in 'sra'. - Any further conversion extensions to
str.format/f-strings/ etc will not require extra work fort-strings- given this is a customisable toolbox (at least this is a promise that I read when I think about them) it would be less coupled and more generic.
At the same time, could do the same for _string.formatter_parser.
Which currently accepts single character without any subset restrictions.
This way, 2 tools that are used for advanced / customisable formatting would be in sync:
- t-strings (immediate variable substitution)
- string.Formatter (delayed variable substitution)
In a way that both provide a consistent backdoor for custom conversions.