Appetite for a backport of strings.Template for python<3.14?

I am wondering if

  • there is already work underway somewhere for a backport of strings.Template for python versions older than 3.14
  • if there isn’t, if anyone has advice on how to make that happen.

I am working on ibis, which is a dataframe API that generates and then executes SQL on various underlying SQL engines. In this recent issue, I think I came across a good use case for strings.Template. But, I want to make this available to users who aren’t using 3.14+.

So, I was wondering if there was a backport for these older python versions, and then we could make ibis accept either implementation (probably using a Protocol for the type hints).

If this doesn’t exist, I’m wondering if there’s appetite from the rest of the community, and suggestions on how to implement this. Maybe take GitHub - asottile-archive/future-fstrings: A backport of fstrings to python<3.6 as inspiration? Other potential gotchas or things to watch out for if I make something?

Thanks all!

3 Likes

I’m pretty sure you’re not referring to the string.Template class, which has been around for a very long time and needs no backporting. Are you asking about string.templatelib which is new in Python 3.14?

2 Likes

Template strings are a new feature in Python 3.14 (not yet released). As such, it won’t be backported by us to a previous version. It might be possible to use tricks à la future-fstrings to do so, but this would be a third-party endeavour. I’m not aware of anyone else who has asked about doing this yet.

A

I have created:

https://pypi.org/project/tstrings-backport/

While creating the package in PyPI, I found another one, which may be more advanced than mine:

https://pypi.org/project/future-tstrings/

2 Likes

Thanks, GitHub - abilian/tstrings-backport: Backport of t-strings (PEP 750) is exactly what I was wondering if it exists. @sfermigier I will continue in the issues of that repository for now to see if it will fit my needs.