PEP 810: Explicit lazy imports

I’m glad to see this revisited, and I’m hoping the explicit version can overcome the prior issues in wanting to make this the default behavior of existing code that relied on imports having side-effects.

I don’t have much to add to this that hasn’t already been extremely well covered by the pep, but there are two things I’d like to chime in on here:

  1. There are some very specific parallel desires with typing that are currently handled (inadequately) by some people by not actually importing (if TYPE_CHECKING: ...), but breaking other introspection in the process. While I don’t think this rises to a level of necessity, and people should be able to use lazy imports in these cases instead, this may warrant a typing-specific extension of the idea that is slightly more inline with the current typing ecosystem if others find it insufficient.

  2. I don’t think the choice of keyword actually matters; lazy and defer (the latter appearing to be a popular alternative in discussion so far) both convey the idea properly enough. “Lazy” is likely the more accurate term, as imports are not deferred; certain aspects of them are lazily evaluated. While I have no strong preference one way or the other, I don’t agree with some prior statements about the word “lazy” being somehow less understood or less professional. The meaning of terms is context-dependent, and the idea of lazy evaluation is not even a Python-specific concept within computing.

6 Likes