[Python-ideas] Delayed Execution via Keyword

Nathaniel Smith njs at pobox.com
Fri Feb 17 21:20:35 EST 2017


On Thu, Feb 16, 2017 at 9:24 PM, Joseph Hackman <josephhackman at gmail.com> wrote:
> Howdy All!
>
> This suggestion is inspired by the question on "Efficient debug logging".
>
> I propose a keyword to mark an expression for delayed/lazy execution, for
> the purposes of standardizing such behavior across the language.
>
> The proposed format is:
> delayed: <expr>
> i.e. log.info("info is %s", delayed: expensiveFunction())

People seem very excited about this as an idea, but I don't understand
how it can be implemented.

For example, how do you propose to handle code like this?

value = delayed: some_dict.get("whatever")
if value is None:
    ...

I.e., the question is, how does 'is' work on delayed objects? I guess
it has to force the promise and walk the proxy chain in each input and
then do an 'is' on the base objects? This seems like a really deep and
confusing change to Python's object model for a pretty marginal
feature. (This is a special case of the general observation that it's
just not possible to implement fully-transparent proxy objects in
Python.)

-n

-- 
Nathaniel J. Smith -- https://vorpus.org


More information about the Python-ideas mailing list