# Builtins.lazy for lazy arguments

**URL:** <https://discuss.python.org/t/builtins-lazy-for-lazy-arguments/86577>\
**Category:** Ideas\
**Created:** [March 31, 2025, 6:01am UTC](https://discuss.python.org/t/builtins-lazy-for-lazy-arguments/86577 "2025-03-31T06:01:37Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![dg-pb](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/dg-pb/32/16248_2.png) [@dg-pb](https://discuss.python.org/u/dg-pb)\
**Post date:** [March 31, 2025, 9:48am UTC](https://discuss.python.org/t/builtins-lazy-for-lazy-arguments/86577/3 "2025-03-31T09:48:40Z")

</div>

> [@xitop](#):
>
> I find the usefulness quite limited, because `lazy` can wrap only a single call. Even a small change is problematic:
> 
> `v = dct.get(k, default=lazy(factorial, 100_000) + 1) # error`

Good point, but lazy isn’t purposed for that. Its sole purpose is to wrap a callable and signal argument being lazy. It can be used in conjunction with other tools to achieve what you have pointed out. Something along the lines of Evaluation graphs would do. E.g.:

```python
v = dct.get(k, default=lazy(dask.deferred(factorial, 100_000) + 1)

```

Or given the fact, that this case is trivial, simple lambda can do:

```python
v = dct.get(k, default=lazy(lambda: factorial(100_000) + 1))

```

> [@xitop](#):
>
> Expressions would require lazy-aware versions of `operator.XXX` (and some infix → prefix rewriting):
> 
> `v = dct.get(k, default=lazy(operator.add, lazy(factorial, 100_000), 1))`

That is also an option.  
In this specific case one could do with something like a `pipe` instead (see: [`functools.pipe`](https://discuss.python.org/t/functools-pipe/69744). It didn’t go through though):

```python
v = dct.get(k, default=lazy(pipe(factorial, partial(add, 1)), 1))

```

But the main point is that for complex cases there are many tools to be used in conjunction.

> [@xitop](#):
>
> I would then prefer:
> 
> `v = dct[k] if k in dct else factorial(100_000) + 1`

This is a good option, however it only works for this specific case of “default return value argument”, but `lazy` is more generic, e.g.:

```python
def ifelse(cond, a, b):
    result = a if cond else b
    if isinstance(result, lazy):
        result = result()
    return result

```

---

_[View the full topic](https://discuss.python.org/t/builtins-lazy-for-lazy-arguments/86577)._
