PEP 690: Lazy Imports

This is worth reiterating, and I think you’ve nailed it right on the head @carljm

Library authors can’t declare their modules safe for lazy import because they have no idea how their libraries are consumed or in what order they will be imported. They can declare they modules unsafe for lazy import but I don’t think that’s actually helpful. As you point out, it leads to essentially every module being unsafe for lazy import in some circumstance or other, and besides that, as a library author myself, I don’t want to modify my code to declare anything about the laziness-friendly property of my library.

As an application author though, I know everything I need to know about what modules I consume, how they are imported, and whether they are safe or not. At least theoretically. Nobody is in a more advantageous position to understand the behavior of my application, and to make declarations about what modules can and cannot be safely lazily imported. And nobody else is in a position to actually test that assumption.

To me, the PEP gives the application author end-consumer the tools they need to build a lazy-friendly application.

5 Likes