Re:PEP 810 – Explicit lazy imports
by WD-42 on Friday October 03, 2025 @11:37PM
(#45470302)
Some of these worries make sense, but wouldn’t it be relatively trivial to pass a flag to the interpreter or something similar in order to force all imports to evaluate, as in the current behavior? But to be a bit cheeky if some of these issues cause serious production outages for you it might be time to consider moving on from a scripting language altogether.
[ Parent
| on HN ]
Re:PEP 810 – Explicit lazy imports
by flare_blitz on Saturday October 04, 2025 @12:07AM
(#45470421)
The issue is that some imports can be made lazy and some cannot. A binaristic all-or-nothing approach does not address the issue. What if we have a program where on feature works only when lazy imports are enabled and one feature only when lazy imports are disabled? This scenario may sound ridiculous, but it is surprisingly easy to write a program that exhibits this behavior, especially in a large codebase.
My point is that many things _will_ break if migrated to lazy imports. Whether they should have been written in Python in the first place is a separate question that isn’t relevant to this discussion.
Theoretically the implementation may use the approach "as lazy as possible". Traverse lazy imports until you encounter a regular one.
I doubt it will make much difference, but at least it gives an option.
Re:PEP 810 – Explicit lazy imports
by paffdragon on Saturday October 04, 2025 @07:42AM
(#45472604)
Maybe the package that requires lazy can somehow declare that requirement, so another package that tries to force not lazy will fail early and realize it needs to replace this dependency with something compatible or change its ways. It definitely adds complexity, though.