Reification of a lazily imported module on a specific case

Hello!

What is the rationale behind triggering the import of the module when it’s internals are not really accessed?

E.g.:

lazy import cmd1
mods = [cmd1]

Thanks!
. Facundo

The decision was made to have lazy imports trigger when the name is retrieved from globals, rather than when the object is subsequently accessed. From the PEP:

Accessing a lazy object (from a global variable or a module attribute) reifies the object.

Adding the module to the list performs this lookup and triggers the import.

Allowing you to put the lazy imports in a list like this without resolving them would essentially require some kind of in-place transformation, while doing so on lookup avoids this. The rejected ideas section in the PEP has an explanation of why they chose not to use a __class__ mutation which covers some of this.

@DavidCEllis thanks!