Skip to content

Instantly share code, notes, and snippets.

@siscia
Created July 1, 2026 02:08
Show Gist options
  • Select an option

  • Save siscia/5549989a8a6cc8529521311471c06aee to your computer and use it in GitHub Desktop.

Select an option

Save siscia/5549989a8a6cc8529521311471c06aee to your computer and use it in GitHub Desktop.
print("executing foo/__init__.py")
print("executing foo/bar.py")
class RandomClass:
print("executing RandomClass body")
def __init__(self) -> None:
print("executing RandomClass.__init__")
print("before lazy import")
lazy from foo.bar import RandomClass
print("after lazy import")
print("before first use")
instance = RandomClass()
print("after first use")
print(f"instance type: {type(instance).__name__}")
simone@simones-Apple-MacBook-Pro tmp.zEmX5KWOEG % uv run python lazy_import_demo.py
before lazy import
after lazy import
before first use
executing foo/__init__.py
executing foo/bar.py
executing RandomClass body
executing RandomClass.__init__
after first use
instance type: RandomClass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment