[Python-ideas] Delayed Execution via Keyword

Joshua Morton joshua.morton13 at gmail.com
Fri Feb 17 18:13:01 EST 2017


@ Joseph

Function annotations can be arbitrary python expressions, it is completely
legal to have something like

    >>> def foo(bar: lambda x: x + 1):
    ...     pass

Why you would want that I can't say, but it is legal. In the same way, `def
foo(bar: delayed 1 + 1)` should probably be legal syntax, even if the use
is inexplicable. (also note that the `:` works with lambda because lambda
cannot be used as an identifier). In any case, as David said, bikeshedding.

@ Ed

Its my understanding that d[k] is always d[k], even if d or k or both are
delayed. On the other hand, `delayed d[k]` would not be, but you would need
to explicitly state that. I think its worth expanding on the example Joseph
made.

I think it makes sense to consider this proposal to be `x = delayed <EXPR>`
is essentially equivalent to `x = lambda: <EXPR>`, except that there will
be no need to explicitly call `x()` to get the delayed value, instead it
will be evaluated the first time its needed, transparently. This, for the
moment, assumes that this doesn't cause enormous interpreter issues, but I
don't think it will. That is, there is no "delayed" object that is created
and called, and so as a user you really won't care if an object is
"delayed" or not, you'll just use it and it will be there.

Do you understand this proposal differently?

--Josh

On Fri, Feb 17, 2017 at 5:35 PM Joseph Hackman <josephhackman at gmail.com>
wrote:

> I think we should use the colon to make the delayed word (or whatever word
> is selected), unambiguously used in this way (and to prevent any existing
> code from breaking).
>
> On 17 February 2017 at 17:09, David Mertz <mertz at gnosis.cx> wrote:
>
> That was a problem with the colon that occurred to me. I think it can't be
> tokenized in function annotations.
>
>
> I don't see any reason for delayed execution and function annotations to
> mix. i.e.
> def foo(delayed: bar):
>     pass
> would define a function that takes one argument, named delayed, of type
> bar.
>
>
>
> Plus I still think the no-colon looks better. But that's bikeshedding.
> Also other words are plausible. I like lazy even more than delayed, I
> think. Still, I'd love the construct whatever the exact spelling.
>
>
> I'm not particularly married to delayed, but I don't know how to properly
> vet this inside the community. I'm glad you like the proposal!
>
> -Joseph
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170217/af4257c7/attachment.html>


More information about the Python-ideas mailing list