markupsafe icon indicating copy to clipboard operation
markupsafe copied to clipboard

Add support for t-strings

Open xmo-odoo opened this issue 3 months ago • 2 comments

Python 3.14 introduces t-strings, a generalisation of f-strings which yields a processable Template object instead of reifying a string. The safety assumption around t-strings is that the literal parts of the template are considered "safe" and the interpolations are considered unsafe. So for markupsafe the literal parts are Markup-ed while the interpolations are escape-ed.

This commit adds support for t-strings to both Markup and escape, essentially matching the handling of __html__.

It does not add support for t-strings to:

  • Markup.__add__ / Markup.__radd__, the semantics seem a bit dubious and it should be easy enough to Markup or escape the t-string / template object in that case.
  • EscapeFormatter as I'm not entirely sure whether / how a template object should interact with format specs.

Fixes #511

xmo-odoo avatar Oct 08 '25 11:10 xmo-odoo

@aleks0099 We do not speak/understand Ukrainian/Russian. Please edit your commends and translate them to English.

ThiefMaster avatar Nov 19 '25 15:11 ThiefMaster

@aleks0099 please do not use an "AI" to "review" PRs. It is not helpful.

davidism avatar Nov 19 '25 16:11 davidism