Y
HN Search
Hacker News Search
new
|
comments
|
top
|
jobs
davepeck
searching PlanetScale…
1.
▲
2.
▲
3.
▲
4.
▲
5.
▲
6.
▲
31 ms
·
61.
▲
by
davepeck
2y ago
Yes, fib_slow() will be evaluated immediately, just like it would be if you were using an f-string.
62.
▲
by
davepeck
2y ago
You can access .strings and .interpolations directly and avoid type checks. There is always one more string than interpolation, of which there may be zero.
63.
▲
by
davepeck
2y ago
Yeah, they’re unrelated. (PEP 750 places its Template and Interpolation classes in the new string.templatelib)
64.
▲
by
davepeck
2y ago
Sure, good point; I generally think of evaluation, not stringification, as the likely dominant expense. But maybe it’s sometimes the other way around?
65.
▲
by
davepeck
2y ago
T-strings, like f-strings, are eagerly evaluated -- so in this sense, no, there's no benefit.
66.
▲
by
davepeck
2y ago
My hope is to write some new documentation as 3.14 nears release that explains the (growing) constellation of string formatting mechanisms in Python and describes when they might each be useful. They overlap to some degree, but each has a u
67.
▲
by
davepeck
2y ago
Yeah. `join` has forever been backwards to me in Python and I still sometimes get it wrong the first time out. Comprehensions, though -- they are perfection. :-)
68.
▲
by
davepeck
2y ago
> assuming an html() function would interpret plain Templates as HTML Agreed; it feels natural to accept plain templates ( and simple sequences of plain templates) as HTML; this is hinted at in the PEP. > html(t"<ul>{map(l
69.
▲
by
davepeck
2y ago
We wanted at least a couple examples that showed use of Python's newer pattern matching capabilities with the new Interpolation type. From this outsider's perspective, I'd say that developer instincts and aesthetic preference
70.
▲
by
davepeck
2y ago
> doesn't specify the language of the template where the literal occurs Yeah, something we spent a bunch of time considering. In the end, we decided it probably needed to stay out of scope for the PEP. You're right that JavaScr
71.
▲
by
davepeck
2y ago
> were prompt templates for LLM prompt chaining a use case that influenced the design in any way Maybe not directly, but the Python community is full of LLM users and so I think there's a general awareness of the issues.
72.
▲
by
davepeck
2y ago
For one thing, `f"something"` is of type `str`; `t"something"` is of type `string.templatelib.Template`. With t-strings, your code can know which parts of the string were dynamically substituted and which were not.
73.
▲
by
davepeck
2y ago
> the Template -> string function There is no such function; Template.__str__() returns Template.__repr__() which is very unlikely to be useful. You pretty much have to process your Template instance in some way before converting to
74.
▲
by
davepeck
2y ago
Yes, exactly. T-string arguments can't be unbound; they are eagerly evaluated.
75.
▲
by
davepeck
2y ago
Naming is hard; for instance, JavaScript also has its own template strings, which are also eagerly evaluated.
76.
▲
by
davepeck
2y ago
You might find the Python discussion forums ([0] and [1]) interesting; conversation that guides the evolution of PEPs happens there. As Nick mentioned, PEP 750 had a long and winding road to its final acceptance; as the process wore on, and
77.
▲
by
davepeck
2y ago
> Agreed, although this doesn't work as well for HTML or SQL that doesn't fit on one line. PEP 750 t-strings literals work with python's tripe-quote syntax (and its lesser-used implicit string concat syntax): lots_of
78.
▲
by
davepeck
2y ago
One place we landed with PEP 750 is that Template instances have no natural string rendering. That is, you must process a Template in some way to get a useful string out the other side. This is why Template.__str__() is spec'd to b
79.
▲
by
davepeck
2y ago
PEP 750 doesn't directly address this because it's straightforward to simply wrap template creation in a function (or a lambda, if that's your style): def my_template(name: str) -> Template: return t"Hel
80.
▲
by
davepeck
2y ago
Yes! PEP 750 landed exactly there: as a pythonic parallel to JavaScript's tagged template strings. I'm hopeful that the tooling ecosystem will catch up soon so we see syntax coloring, formatting of specific t-string content types,
81.
▲
by
davepeck
2y ago
I'm not sure I agree with this analysis. Template.__str__() is equivalent to Template.__repr__(), which is to say that these aren't f-strings in an important sense: you can't get a useful string out of them until you proces
82.
▲
by
davepeck
2y ago
> I'm not sure if t-strings help here? That's correct, they don't. Evaluation of t-string expressions is immediate, just like with f-strings. Since we have the full generality of Python at our disposal, a typical solution
83.
▲
by
davepeck
2y ago
Good news on that front! https://discuss.python.org/t/pep750-template-strings-new-upd...
84.
▲
by
davepeck
2y ago
Slowly but surely... PEP 750 (still a proposal) adds "t-strings" Python. They're a simple extension of f-strings that give developers access to the static and interpolated parts of the string before they get combined into a
85.
▲
by
davepeck
2y ago
For what it’s worth: I believe they will prove ineffective at best, damaging at worst. I believe disruptive change should be undertaken with a deep understanding of the history of an organization and a clear-eyed accounting of its successes
86.
▲
by
davepeck
2y ago
There are effective approaches to curbing fraud waste and abuse and ineffective or even damaging approaches. Which do you believe the current administration is engaged in?
87.
▲
by
davepeck
2y ago
Who said anything about a hidden agenda? Can you consider that the current efforts are outright foolish?
88.
▲
by
davepeck
2y ago
> The way you combat the creep of bureaucratic miasma is by regularly turning a critical eye inward It certainly can’t hurt. Alas for the current moment, but it seems the eye we’re turning inward is as far from “critical” as can be.
89.
▲
by
davepeck
2y ago
And to be clear, they also flew to Taiwan and interviewed Morris in English for what appears to be the first time in over 15 years: https://www.acquired.fm/episodes/tsmc-founder-morris-chang A tiny bit of this (excelle
90.
▲
by
davepeck
2y ago
“Their apps are horrendous.” I’ll give a counterpoint: with a subscription, Apple Music for iPad is quite literally the best personal music exploration/listening app on the market. A quiet room and good pair of headphones is all the re
More ›