[Python-ideas] Delayed Execution via Keyword
mertz at gnosis.cx
Sat Feb 18 00:34:08 EST 2017
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. If
the next line after creating delayed 'value' is to check it against
something (whether for equality or identity) then obviously it was
pointless to make it delayed. But that's not the only pattern:
value = delayed some_dict.get(expensive_key_lookup(),
... lots more code ...
# OK, there might come a time to concretize
if some_unrelated_thing and value is None:
# do this, but only concretize 'value' if
# the first part of conjunction was truthy
Keeping medicines from the bloodstreams of the sick; food
from the bellies of the hungry; books from the hands of the
uneducated; technology from the underdeveloped; and putting
advocates of freedom in prisons. Intellectual property is
to the 21st century what the slave trade was to the 16th.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas