PEP 810: Explicit lazy imports

We’ve updated the PEP with a lot of clarifications, small renames, and several explicitly documented rejected ideas (all based on the feedback here and from private discussions). Many of the comments in this thread helped us refine the explanations and make the document clearer and more precise so thanks a lot :heart:

After discussing with the team extensively and reading through all the feedback, we’ve made a couple of updates based on what we’ve learned from the conversation:

• Lazy imports inside with blocks
We’ve decided to allow them. There are many legitimate use cases where with is used for managing lifetime or scoping behavior rather than just suppressing exceptions, and the syntax is explicit enough that users know what they’re doing. It fits Python’s “consenting adults” model as with carries broader semantics than just error handling. For the genuinely problematic cases (like contextlib.suppress(ImportError)), we think linters are the right abstraction to catch them rather than hard language restrictions.

__dict__ and reification
We’ve also pivoted to not automatically reify on __dict__ access. This makes the model cleaner: __dict__ is already a low-level API, and introspection code generally shouldn’t trigger side effects implicitly. It’s a better mental model to ask users to reify explicitly when they need it, rather than forcing them into awkward patterns just to avoid automatic behavior. This decision also came out naturally when we had to make parts of the stdlib reason about this (for example, in the traceback module) as it quickly became clear that automatic reification was cumbersome and not the right thing to do. This also restores nice symmetry with globals(): both now expose the raw namespace view, and both are easy to explain and predict.

Thanks again to everyone who shared thoughts, questions, and concerns regarding this! All this feedback genuinely makes a difference and helps us refine the proposal into something better for everyone.

We will be updating the PEP shortly.

35 Likes