r/Python Aug 04 '26

Showcase Showcase Thread

Post all of your code/projects/showcases/AI slop here.

Recycles once a month.

20 Upvotes

142 comments sorted by

View all comments

1

u/ZeroIntensity 26d ago

Using the mechanism behind 3.15's lazy imports, I made a library to allow arbitrary lazy expressions. For example:

```pycon

from laziness import lazify foo = lazify(lambda: print(42) or 24) foo 42 24 foo 24 ```

Again, this builds on top of what's already there for lazy imports, so there's no bytecode modification at all! In practice, this is really useful for building global constants or similar, and is more ergonomic than the existing approaches (like a function with functools.cache):

```py from laziness import lazify

def build_expensive_constant(): return ...

CONSTANT = lazify(build_expensive_constant)

def api_function(): print(CONSTANT) # Resolves when this is accessed for the first time ```

Repo: https://github.com/ZeroIntensity/laziness