←back to thread

620 points tambourine_man | 1 comments | | HN request time: 0.219s | source
Show context
florbnit ◴[] No.43754419[source]
> In addition, I hope that the tooling ecosystem will adapt to support t-strings. For instance, I’d love to see black and ruff format t-string contents, and vscode color those contents, if they’re a common type like HTML or SQL.

This is such a strange take on t-strings. The only way for anything to infer that the template string is supposed to turn into valid HTML or SQL is to base it of the apparent syntax in the string, which can only be done in an ad-hoc fashion and has nothing to do with the template string feature.

The way the feature has been designed there is no indication in the string itself what type of content it is or what it will eventually be converted to. It’s all handled by the converting function.

As others have added, something like sql”select * from {table}” would have been able to do this, but there’s not even any guarantees that something that is in a template that will be converted into valid sql by a converting function should be any type of valid sql prior to that conversion. For all you know t“give me {table} but only {columns}” might be a converted into valid sql after the template is processed.

replies(7): >>43754586 #>>43754693 #>>43754745 #>>43754827 #>>43755016 #>>43755210 #>>43757519 #
pphysch ◴[] No.43754693[source]
Python has had type annotations for a decade, and modern IDEs can interpret them.

Writing `query: SQL = t"SELECT ..."` is a small price to pay for such a DX boost.

replies(1): >>43859493 #
1. florbnit ◴[] No.43859493[source]
I mean yes, so t-strings add nothing.

You could already do everything you are proposing t-strings will make easier with just strings or f-strings.

‘query: SQL “Select …”’

“Wait” you’ll say “then the function taking the string has to parse the string and will have to add ugly logic grabbing variables from globals()!” Ah yes. That’s such an ugly solution… let’s instead codify just that as the official best practice and sell people on it by prefixing a t to the string so they don’t notice…