Skip to content

Templated strings#2698

Open
scauligi wants to merge 11 commits intohylang:masterfrom
scauligi:tstrings
Open

Templated strings#2698
scauligi wants to merge 11 commits intohylang:masterfrom
scauligi:tstrings

Conversation

@scauligi
Copy link
Copy Markdown
Member

@scauligi scauligi commented Apr 12, 2026

Python 3.14 introduced t-strings as a new literal type.

This PR allows parsing t-strings, as well as introduces a new pragma bracketed-templates to additionally allow bracketed t-strings (a la bracketed f-strings).

@Kodiologist
Copy link
Copy Markdown
Member

Looks like you gotta gate the tests to Python 3.14.

@Kodiologist
Copy link
Copy Markdown
Member

I don't think you need pytest_ignore_collect for this. In an analogous way that I guard some files with do-mac, you can prefix your file with a reader macro like so:

(defreader r []
  (if hy.compat.PY3-14
    `(do ~@(.parse-forms-until &reader ""))
    (for [_ (.chars &reader True)])))

#r

@scauligi
Copy link
Copy Markdown
Member Author

you can prefix your file with a reader macro like so

oh very cute, I like that

@Kodiologist
Copy link
Copy Markdown
Member

Kodiologist commented Apr 12, 2026

I force-pushed to group some logically related commits together.

I think you might be gating for Python 3.14 in Hy itself a bit too aggressively. There's no reason that the Hy syntax t"foo" needs to be illegal in Python 3.13, for example. The Hy-level syntax and models for t-strings don't require support from Python. The only place we should need to check the Python version is in the compiler functions, when the user tries to compile a Hy t-string into a Python-level t-string. As a bonus, you'll no longer need a reader macro to gate the tests, and some tests won't need to be gated.

By the way, does it make sense for t-strings to by represented as hy.models.FStrings, instead of getting their own model type? That seems confusing.

It looks like hy-repr for t-strings isn't tested.

I think (= (type t1) (type t2) Template) would be better written with is instead of =.

Finally, of course, we'll need documentation.

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.

3.14 Template Strings

2 participants