On Sun, Oct 31, 2021 at 2:20 PM Rob Cliffe via Python-ideas <python-ideas@python.org> wrote: > As for deferred evaluation objects: > First, Python already has various ways of doing deferred evaluation: > Lambdas > Strings, which can be passed to eval / exec / compile. > You can write decorator(s) for functions to make them defer their > evaluation. > You can write a class of deferred-evaluation objects. > None of these ways is perfect. Each have their pros and cons. The bottom > line, if I understand correctly (maybe I don't) is that there has to be a way > of specifying (implicitly or explicitly) when the (deferred) evaluation > occurs, and also what the evaluation context is (e.g. for eval, locals and > globals must be specified, either explicitly or implicitly). >
That last part is the most important here: it has to be evaluated *in the context of the function*. That's the only way for things like "def f(a, n=len(a)):" to be possible. Every piece of code in Python is executed, if it is ever executed, in the context that it was written in. Before f-strings were implemented, this was debated in some detail, and there is no easy way to transfer a context around usefully. ChrisA _______________________________________________ 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/VDPRQQLYEGVTDJPJAOJAQPGUNKKYBYZ7/ Code of Conduct: http://python.org/psf/codeofconduct/