Skip to content

Support Template Strings for log messages (#1397)#1398

Merged
Delgan merged 2 commits into
Delgan:masterfrom
TurtleOrangina:support_template_strings
Jun 13, 2026
Merged

Support Template Strings for log messages (#1397)#1398
Delgan merged 2 commits into
Delgan:masterfrom
TurtleOrangina:support_template_strings

Conversation

@TurtleOrangina

@TurtleOrangina TurtleOrangina commented Oct 7, 2025

Copy link
Copy Markdown

Implements support for python 3.14 template strings:

logger.debug(t"obj = {large_obj}")

Will evaluate lazily, e.g. if the minimum log level means no debug messages are logged, the large_obj will not be converted to string.

@TurtleOrangina TurtleOrangina force-pushed the support_template_strings branch 2 times, most recently from 8ebac5d to 5bcc344 Compare October 7, 2025 17:51
@Delgan

Delgan commented Oct 8, 2025

Copy link
Copy Markdown
Owner

Thank you for this initial implementation. This seems like an excellent solution to compensate for the planned removal of **kwargs as a formatting argument.

Please allow me not to merge this PR immediately because I want to think a little about possible integrations of t-strings, but it seems very fine to me as is.

@TurtleOrangina

Copy link
Copy Markdown
Author

Of course! Let me know if you want any changes.

@TurtleOrangina

Copy link
Copy Markdown
Author

2 month reminder :). I read in a different PR that you are working on some larger refactoring, but wouldn't it make sense to get the simpler things that are already ready merged and maybe make a minor release with them? I would sure enjoy the ability to use logger.debug(t"obj = {large_obj}") in my python 3.14 projects :).

@gipfelen

Copy link
Copy Markdown

Hi! Just checking in to see if there are any updates on this PR. It would be a handy addition for a project I’m currently working on. Thanks!

@Delgan

Delgan commented Mar 11, 2026

Copy link
Copy Markdown
Owner

Sorry for the delay... I'll test it, merge it and publish a new release by the end of the month.

@Delgan Delgan force-pushed the support_template_strings branch from 5bcc344 to 33adce0 Compare March 29, 2026 17:35
@Delgan Delgan force-pushed the support_template_strings branch 3 times, most recently from 4df1e09 to 33ab52a Compare April 11, 2026 08:29
Peter Kirk and others added 2 commits June 13, 2026 17:19
Notably:
- Fix support for t-strings with `opt(colors=True)`
- Handle nested t-strings properly
- Implement formatting of t-string in tracebacks (new tokens)
- Update the type hints stub to accept t-strings
- Mention t-strings in documentation
- Add many more unit tests in dedicated file
@Delgan Delgan force-pushed the support_template_strings branch from 33ab52a to fcee187 Compare June 13, 2026 15:21
@Delgan Delgan merged commit 3fb23a4 into Delgan:master Jun 13, 2026
21 checks passed
@Delgan

Delgan commented Jun 13, 2026

Copy link
Copy Markdown
Owner

Finally merged this. Thanks for the contribution and sorry for the long wait.

This feature wasn't as trivial as it might seem, and required a subsequent commit, see 3fb23a4. But everything should work properly.

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 participants