Skip to content

t-strings support #511

@xmo-odoo

Description

@xmo-odoo

With the release of Python 3.14, t-strings (PEP 750) seem well suited to markupsafe e.g.

Markup(t'foo {bar} baz')

should be similar to

Markup("foo %s baz") % bar

possibly easier to lint and typecheck.

While it would work nicely by just adding __html__ to string.templatelib.Template, that is not an option:

>>> Template.__html__ = None
...
TypeError: cannot set '__html__' attribute of immutable type 'string.templatelib.Template'

so sadly in order for this to work markupsafe needs dedicated support.

Open question: should escape(t'foo {bar} baz') behave the same as Markup(t'foo {bar} baz')? That would parallel the __html__ protocol, which I think is reasonable.

I'd be glad to contribute this, I already have the start of an implementation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions