4 ms·
I think that, since you don't allow `sql(t"SELECT {a-1}")`, you should allow `sql(t"SELECT {}", a - 1)`, as long as that is possible with t-strings. This would
by ilyagr 1y ago
I think that, since you don't allow `sql(t"SELECT {a-1}")`, you should allow `sql(t"SELECT {}", a - 1)`, as long as that is possible with t-strings. This would be similar to Rust's `format!` then.
- ilyagr 1y agoAh, apparently with real t-strings, `t"SELECT {a-1}"` should be allowed while `t"SELECT {}"` is not. Here is Python master branch: Python 3.15.0a0 (heads/main:ea2d707bd5, May 16 2025, 12:20:56) [Clang 16.0.0 (clang-1600.0.26.6)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> t"Hello {a}" Traceback (most recent call last): File "<python-input-1>", line 1, in <module> t"Hello {a}" ^ NameError: name 'a' is not defined >>> a=3 >>> t"Hello {a+5}" Template(strings=('Hello ', ''), interpolations=(Interpolation(8, 'a+5', None, ''),)) >>> t"Hello {}" File "<python-input-6>", line 1 t"Hello {}" ^ SyntaxError: t-string: valid expression required before '}'