PEP 787: Safer subprocess usage using t-strings

One of the advantages of template processors is that it’s relatively straightforward to add further type handling later (as long as unknown input types raise exceptions when processed). For example, if tuples were added as a valid substitution field value type, then interpolating a dynamic list of arguments might look like:

if option:
    options = ("-l", "-h")
else:
    options = ()
magic_split_function(t"ls {options} {dirname}/{fname}")

(accepting arbitrary iterables can be a bit more problematic, since that’s such a broad type it can significantly reduce your flexibility in changing the interpretation of other types in later API updates)

1 Like