That looks like a good start.
I think DeferExpr
needs *args
and **kwds
.
This way:
result = list()
for a in range(10):
b = DeferExpr(operator.add, a, 1)
result.append(DeferExpr(operator.add, b, 1))
lazy_result_sum = DeferExpr(sum, result)
Also, I think DeferExpr
needs a more convenient name.
Personally, I probably would use it more than potential syntactic convenience for no-arg version.
After all, it seems that b = d"a + 1"
is just syntactic convenience for special case b = DeferExpr(lambda: a + 1)
.
DeferExpr
is essentially functools.lazy
concept from before, maybe naming it lazy
or deferred
would be appropriate.
Its signature is similar to partial(func, *args, **kwds)
, while this also potentially has lazy(func, *args, **kwds)
, so this naming pattern would make things consistent.
Also, not sure what would be best location for such. From functionality POV functools
seems good place.
However, given that this would most likely not have its pure Python version, it might be better to create a new module for it, e.g. proxies
.
All in all, I would strongly suggest splitting this into 2 parts:
- Nail down
DeferExpr
object - Then figure out syntactic conveniences and possible additions to
builtins
All the important details to figure out are in DeferExpr
concept.
And there is a high risk that syntax changes will be rejected.
And if DeferExpr
is bundled with such, the whole thing will be rejected.