Skip to content

Conversation

pablogsal
Copy link
Member

@pablogsal pablogsal commented Oct 13, 2025

This commit updates PEP 810 based on team discussion and feedback:

  1. Allow lazy imports inside with blocks

    • Removed with blocks from syntax restrictions
    • Added rejected ideas section explaining why restriction was considered
  2. dict does not automatically reify lazy imports

    • Both globals() and __dict__ return raw dictionary without reification
    • Updated reification section, FAQ, and rejected ideas

📚 Documentation preview 📚: https://pep-previews--4656.org.readthedocs.build/

This commit updates PEP 810 based on team discussion and feedback:

1. Allow lazy imports inside with blocks
   - Removed with blocks from syntax restrictions
   - Added rejected ideas section explaining why restriction was considered

2. __dict__ does not automatically reify lazy imports
   - Both globals() and __dict__ return raw dictionary without reification
   - Updated reification section, FAQ, and rejected ideas
Copy link
Member

@pganssle pganssle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with block stuff LGTM, except for one note.

tools and linters are better suited to catch these patterns than hard language
restrictions.

Additionally, forbidding explicit ``lazy import`` in ``with`` blocks would
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is any more true than the try/except case, no? It's not really more complexity than the current PEP unless you also have the part where implicit lazy is forced eager in with blocks.

does **not** automatically reify lazy imports -- you'll see the lazy proxy
objects themselves, which you can then manually resolve if needed.

What's the difference between ``globals()`` and ``mod.__dict__`` for lazy imports?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This entire question now doesn't make sense anymore. There isn't a difference between them, is there? Can we just remove this FAQ entry?

pablogsal and others added 3 commits October 13, 2025 20:30
Co-authored-by: T. Wouters <thomas@python.org>
Co-authored-by: T. Wouters <thomas@python.org>
Co-authored-by: T. Wouters <thomas@python.org>
# Accessing __dict__ from external code DOES reify all lazy imports
d = my_module.__dict__
the object.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lint fix

Suggested change
the object.
the object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants