[Python-ideas] Delayed Execution via Keyword
Sven R. Kunze
srkunze at mail.de
Sun Feb 19 05:59:11 EST 2017
I would like to add another view of this feature might be very useful
for cleaning up existing code bases:
Just have a look at https://pypi.org/project/xfork/ and specifically I
would like to point you to the following lines
https://github.com/srkunze/fork/blob/afecde0/fork.py#L216 till #419.
As you can see these whooping 203 lines are for the sake of implementing
a delaying proxy class (of a 520 lines project).
If this feature gets added, the almost the whole implementation could
*shrink to a mere line* of (I hope):
That would be awesome!
Btw. adding parameters to 'delayed' like lambda would also be useful. [I
gather that delayed is a mere placeholder for now.]
On 18.02.2017 12:10, Nathaniel Smith wrote:
> On Fri, Feb 17, 2017 at 9:34 PM, David Mertz <mertz at gnosis.cx> wrote:
>> On Fri, Feb 17, 2017 at 6:20 PM, Nathaniel Smith <njs at pobox.com> wrote:
>>> 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?
>> You've explained the semantics exactly. That's not confusing at all.
> Okay... so what if I want to check if two objects refer to the same
> delayed computation? I guess you can say that's just not supported,
> but that's *extraordinarily weird* for Python.
It's new to Python yes, but it's not weird. You already can implement
such proxies today as I've demonstrated.
> And at the implementation level... so you just added two type checks
> and two branches to every 'is' call; this seems concerning. And now
> 'is' can raise an error, which it never could before. You also AFAICT
> have to modify every single C extension function to check for and
> handle these things, which is probably impossible even if the overhead
> of all the checks is acceptable, which isn't obvious. I'm just not
> seeing how this could be implemented.
I don't share your concerns here. What you describe is the nature of
*delayed*. It's not only applicable to 'is' but to all operations which
evaluate delayed objects.
My point of view from the other side: me and other people need delayed
proxies, so they implement them, and all of us make the same mistakes
over and over gain.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas