PEP 810 introduces explicit lazy imports to Python 3.15 via a new `lazy` keyword. Lazy imports defer module loading until the imported name is actually accessed, solving three problems: startup performance (especially for CLI tools), unnecessary imports used only for type annotations, and some circular import cycles. The video demonstrates profiling import times with the `import-time-waterfall` tool, shows practical usage with a real CLI project, and covers key pitfalls — notably that lazy imports defer ImportError until access time, meaning broken imports won't surface until runtime. A `__lazy_modules__` dunder variable is also available for backward-compatible lazy imports in older Python versions.
•21m watch time
404 Impressions