On Mon, Jul 5, 2021 at 5:05 PM Chris Angelico <ros...@gmail.com> wrote:
> On Tue, Jul 6, 2021 at 9:39 AM Greg Ewing <greg.ew...@canterbury.ac.nz> > wrote: > > > > On 6/07/21 9:56 am, Jim Baker wrote: > > > > > > d = deferred_tag"Some expr: {:(x*2)}" > > > > > > All that is happening here is that this being wrapped in a lambda, > which > > > captures any scope lexically as usual. > > > > Is there reason to think this will be a common enough requirement > > to justify having an abbreviated syntax for a parameterless lambda > > that's only available in template expressions? > > > > If it's just being wrapped in a lambda function, probably nothing, but > I think that that would be *very* surprising behaviour. People will > expect that the expressions' values will be collected at the point you > hit the interpolated string, not later when it gets used. > It would be surprising indeed if this was the *default* behavior, that's why you have to specially mark it using {:...} in Jim's proposal. IIUC the idea is that the entire template becomes effectively a lambda. It's useful if the evaluation is relatively expensive and may never be needed, e.g. for logging at a level that is off in production. We can debate whether it's better to mark individual substitutions with something like {:...} or whether we should mark the template as a whole (obviously the marking must be understandable by the parser). -- --Guido van Rossum (python.org/~guido) *Pronouns: he/him **(why is my pronoun here?)* <http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-change-the-world/>
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/TUAFAIOH2WEHZOKQZ4RF2M6H6KVI7CMY/ Code of Conduct: http://python.org/psf/codeofconduct/