# PEP 810: Explicit lazy imports

**URL:** <https://discuss.python.org/t/pep-810-explicit-lazy-imports/104131>\
**Category:** PEPs\
**Created:** [October 3, 2025, 11:50am UTC](https://discuss.python.org/t/pep-810-explicit-lazy-imports/104131 "2025-10-03T11:50:19Z")\
**Posts on this page:** 1\
**Showing post:** 261

<div class="post-metadata">

**Author:** ![pganssle](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/pganssle/32/245_2.png) [@pganssle](https://discuss.python.org/u/pganssle)\
**Post date:** [October 9, 2025, 3:18am UTC](https://discuss.python.org/t/pep-810-explicit-lazy-imports/104131/261 "2025-10-09T03:18:22Z")

</div>

> [@ncoghlan](#):
>
> Nay, as the backport syntax will necessarily use regular import statements, not lazy ones. One potential implementation strategy would be to override the regular ` __import__ ` inside the context with one that maps to ` __lazy_import__ `. That would require some careful design to avoid having things blow up if reification is attempted while the context is still open, though. Maybe ` __lazy_modules__ = ["*"]` could be allowed, so the context manager could just temporarily set that instead of messing with ` __import__ `?

So I was less than clear in my reasoning here, but my understanding is that in the current model, when ` __lazy_modules__ ` is set, it will _not_ lazily import in a context, but it also won’t be a syntax error, so:

```python
__lazy_modules__ = ["foo", "bar"]

import foo # lazy

with blah():
    import bar # eager

```

If we change it so that both of these are lazy, then I think that `lazy import …` should also be allowed in the `with` block as well, because otherwise I think people will think “well lazy importing isn’t allowed in context managers so obviously this is eager”.

If however we allow lazy imports in a context manager, you don’t need any hacks in Python 3.15 and no careful thought needs to be done about replacing ` __import__ ` with ` __lazy_import__ `, because it will just work out of the box once ` __lazy_import__ ` exists, and the hacks can all go into the backport.

---

_[View the full topic](https://discuss.python.org/t/pep-810-explicit-lazy-imports/104131)._
