(self, attr)
return getattr(self, attr)
Trigger the load of the module and return the attribute.
Trigger the load of the module and return the attribute.
Trigger the load of the module and return the attribute .
def __getattribute__(self, attr):
        """Trigger the load of the module and return the attribute."""
        # All module metadata must be garnered from __spec__ in order to avoid
        # using mutated values.
        # Stop triggering this method.
        self.__class__ = types.ModuleType
        # Get the original name to make sure no object substitution occurred
        # in sys.modules.
        original_name = self.__spec__.name
        # Figure out exactly what attributes were mutated between the creation
        # of the module and now.
        attrs_then = self.__spec__.loader_state['__dict__']
        attrs_now = self.__dict__
        attrs_updated = {}
        for key, value in attrs_now.items():
            # Code that set the attribute may have kept a reference to the
            # assigned object, making identity more important than equality.
            if key not in attrs_then:
                attrs_updated[key] = value
            elif id(attrs_now[key]) != id(attrs_then[key]):
                attrs_updated[key] = value
        self.__spec__.loader.exec_module(self)
        # If exec_module() was used directly there is no guarantee the module
        # object was put into sys.modules.
        if original_name in sys.modules:
            if id(self) != id(sys.modules[original_name]):
                raise ValueError(f"module object for {original_name!r} "
                                  "substituted in sys.modules during a lazy "
                                  "load")
        # Update after loading since that's what would happen in an eager
        # loading situation.
        self.__dict__.update(attrs_updated)
        return getattr(self, attr)
def __getattribute__ ( self , attr ) : # All module metadata must be garnered from __spec__ in order to avoid # using mutated values. # Stop triggering this method. self . __class__ = types . ModuleType # Get the original name to make sure no object substitution occurred # in sys.modules. original_name = self . __spec__ . name # Figure out exactly what attributes were mutated between the creation # of the module and now. attrs_then = self . __spec__ . loader_state [ '__dict__' ] attrs_now = self . __dict__ attrs_updated = { } for key , value in attrs_now . items ( ) : # Code that set the attribute may have kept a reference to the # assigned object, making identity more important than equality. if key not in attrs_then : attrs_updated [ key ] = value elif id ( attrs_now [ key ] ) != id ( attrs_then [ key ] ) : attrs_updated [ key ] = value self . __spec__ . loader . exec_module ( self ) # If exec_module() was used directly there is no guarantee the module # object was put into sys.modules. if original_name in sys . modules : if id ( self ) != id ( sys . modules [ original_name ] ) : raise ValueError ( f"module object for {original_name!r} " "substituted in sys.modules during a lazy " "load" ) # Update after loading since that's what would happen in an eager # loading situation. self . __dict__ . update ( attrs_updated ) return getattr ( self , attr )