I think the PEP looks great. Like this post above mentioned, I think a common use case for deferred imports is for optional dependencies, so I wondered about the best pattern for testing for import errors. Before one might have:
def some_func():
try:
import numpy
except ImportError as exc:
raise RuntimeError("numpy is required for using some_func!") from exc
It seems like the new pattern would be:
lazy import numpy
def some_func():
try:
globals()["numpy"].get()
except ImportError as exc:
raise RuntimeError("numpy is required for using some_func!") from exc
Perhaps for optional imports where you want to check for import errors there is not much benefit to the new syntax over the old pattern of putting an import into each function that needed the optional import? There is still a modest benefit to grouping all imports at the top of the file instead of hiding them in functions.