Skip to content

(Python) Template strings (t-strings, PEP 750) not properly highlighted #4325

@TethysPlex

Description

@TethysPlex

Describe the issue

Python 3.14 introduce template strings (t-strings) as defined in PEP 750. Template strings use the t prefix (similar to f-strings' f prefix) but are not currently recognized by Highlight.js. This results in incorrect syntax highlighting where the t prefix and the template string syntax are not properly distinguished from regular strings.

Which language seems to have the issue?

python

Are you using highlight or highlightAuto?

Both highlight and highlightAuto are affected.

Sample Code to Reproduce

from string.templatelib import Template, Interpolation

# Basic template string
name = "World"
template = t"Hello {name}"

# Template string with conversion
message = t"Hello {name!r}"

# Template string with format spec
value = 42
formatted = t"Value: {value:.2f}"

# Raw template string
trade = 'shrubberies'
raw_template = rt'Did you say "{trade}"?\n'

# Debug specifier
debug_template = t"Hello {name=}"

# Template concatenation
combined = t"Hello " + t"{name}"
implicit = t"Hello " t"{name}"

Expected behavior

The syntax highlighting should recognize:

  1. The t and T prefixes as valid string prefixes (similar to f, r, b)
  2. The combination rt and tr prefixes for raw template strings
  3. Template strings should be highlighted similarly to f-strings, with:
    • The string prefix (t, T, rt, tr) highlighted as a keyword
    • Interpolation expressions inside {...} properly highlighted
    • Support for conversion specifiers (!r, !s, !a)
    • Support for format specifiers (: followed by format spec)
    • Support for the debug specifier (=)

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions