Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add support for t-strings#512

Open
xmo-odoo wants to merge 1 commit into
pallets:main from
xmo-odoo:t-strings
Open

Add support for t-strings #512
xmo-odoo wants to merge 1 commit into
pallets:main from
xmo-odoo:t-strings

Conversation

@xmo-odoo

@xmo-odoo xmo-odoo commented Oct 8, 2025

Copy link
Copy Markdown

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

Python 3.14 introduces [t-strings][PEP750], 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 pallets#511
[PEP750]: https://peps.python.org/pep-0750/ 

This comment was marked as outdated.

This comment was marked as outdated.

@pallets pallets deleted a comment from aleks0099 Nov 19, 2025
@pallets pallets deleted a comment from aleks0099 Nov 19, 2025
@pallets pallets deleted a comment from aleks0099 Nov 19, 2025
@pallets pallets deleted a comment from aleks0099 Nov 19, 2025
@pallets pallets deleted a comment from aleks0099 Nov 19, 2025
@pallets pallets deleted a comment from aleks0099 Nov 19, 2025
@pallets pallets deleted a comment from aleks0099 Nov 19, 2025

This comment was marked as off-topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

t-strings support

AltStyle によって変換されたページ (->オリジナル) /