-
-
Notifications
You must be signed in to change notification settings - Fork 34.7k
__future__ imports aren't always eager #151577
Copy link
Copy link
Open
Labels
3.15pre-release feature fixes, bugs and security fixespre-release feature fixes, bugs and security fixes3.16new features, bugs and security fixesnew features, bugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-lazy-importstype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Metadata
Metadata
Assignees
Labels
3.15pre-release feature fixes, bugs and security fixespre-release feature fixes, bugs and security fixes3.16new features, bugs and security fixesnew features, bugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-lazy-importstype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Fields
Give feedbackNo fields configured for issues without a type.
Bug report
It's my understanding that
__future__imports are always supposed to be eager. PEP 810 even goes so far as to specifically excludelazy from __future__ import ...syntax:However, the current implementation on
3.15andmaindoes allow__future__imports to become lazy when lazy imports are globally enabled:I have a patch that flags these imports as not-lazy-eligible in the bytecode compiler (similar to
*imports, imports intryblocks, and non-module-level imports). Backporting this fix to 3.15 would require bumping the bytecode magic number, though (it can be checked at runtime, but that likely introduces some overhead). Just thought I'd check to make sure my understanding is correct here and that this is indeed a bug.