news.volyx.in

Python’s new t-strings (davepeck.org)

620 points by tambourine_man · 467 days ago · 466 comments on HN

Article summary

Python 3.14 will introduce a new feature called t-strings, which are similar to f-strings but provide a safer and more flexible way of processing strings. T-strings result in a Template object that allows access to the parts of the string, making it possible to write code that processes strings in a more secure way. This feature is expected to be useful for libraries and frameworks that deal with user input, such as SQL queries and HTML templating. T-strings will be available in Python 3.14, scheduled for release in October 2025.

Main themes

  • Python 3.14 features
  • t-strings
  • string processing
  • security
  • SQL queries
  • HTML templating

What commenters say

  • The introduction of t-strings may lead to a more crowded syntax with multiple string prefixes, potentially affecting readability in large codebases.
  • T-strings provide a more secure way of processing strings, especially when dealing with user input, by allowing libraries to safely escape interpolated values.
  • The use of t-strings may not be significantly different from using a function that operates on a string, but the syntactic sugar of the t-string prefix can provide benefits such as improved syntax highlighting and linting.
  • Some developers are concerned that the introduction of new language features may break existing code or cause compatibility issues, while others believe that it is time to move on from the Python 2 to 3 transition and embrace new features.
  • T-strings are seen as a powerful tool for building libraries and frameworks that deal with user input, and their ability to provide a safer and more flexible way of processing strings is a significant advantage.
  • The concept of prefixes in Python syntax is debated, with some finding it deviant from readable code and others seeing it as a useful way to provide additional functionality.
  • The ability to use t-strings to build libraries that safely process user input, such as SQL queries and HTML templating, is a significant benefit of this new feature.