News for hackers. Stuff that matters.
Re:Python's new t-strings by mcintyre1994 on Monday April 21, 2025 @06:36AM (#43750323)
Any sane library will just error when you pass a string to a function that expects a template though. And that library will have types too so your IDE tells you before you get that far.
Re:Python's new t-strings by Dx5IQ on Monday April 21, 2025 @10:33AM (#43752466)
Such library functions tend to also accept a string as a valid input. E.g. db.execute from the GP usually works with strings to allow non-parametrized SQL queries.
Re:Python's new t-strings by kccqzy on Monday April 21, 2025 @11:12AM (#43752850)
The library should just refuse strings. If a non parametrized query is desired, it could require the user to supply a t-string with no {}.
Re:Python's new t-strings by dragonwriter on Wednesday April 23, 2025 @02:29AM (#43769225)
> Such library functions tend to also accept a string as a valid input.

Also? They tend only to accept a string (possibly with some additional arguments, if there is an in-library way to handle parameterization) as input, because Template literally hasn't been an option. New APIs designed with Template available will look different.

Re:Python's new t-strings by _Algernon_ on Monday April 21, 2025 @11:59AM (#43753438)
This would break backwardcompatibility pretty hard. In many cases it may not be worth it.
Re:Python's new t-strings by eichin on Monday April 21, 2025 @12:54PM (#43753990)
But now at least the language has the necessary rope (and an opportunity for a cultural push to insist on it.)
Re:Python's new t-strings by hombre_fatal on Monday April 21, 2025 @01:51PM (#43754551)
Javascript already has prior art here.

A library can extend an existing database library like 'pg' so that PgClient#query() and PgPool#query() require string template statements.

That way 'pg' can continue working with strings, and people who want nice templated strings can use the small extension library, and the small extension library makes it impossible to accidentally pass strings into the query functions.