Skip to content

Conversation

koxudaxi
Copy link

@koxudaxi koxudaxi commented May 29, 2025

Adds parsing support for PEP 750 Template Strings, a new Python 3.14 feature that introduces t-strings for safer templating.

Overview

Template strings use the t prefix and create Template objects instead of regular strings, enabling secure HTML/SQL templating and DSL support:

# Basic template string
name = "world"
template = t"Hello, {name}!"

# Multi-line with format specifiers
html = t"""
<div class="user">
    <h1>{user.name}</h1>
    <p>Score: {score:04d}</p>
</div>
"""

Changes

  • Added Template flag to scanner for t-prefixed string literals
  • Extended scanner to recognize t/T prefixes (supports tr/rt combinations)
  • Template strings reuse existing f-string interpolation mechanism
  • Added comprehensive test coverage with 8 test cases

Related

Template strings will be available in Python 3.14.0b1+ and officially released in Python 3.14.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant