Load the module and insert it into the parent's globals.
(self)
| 40 | super(LazyLoader, self).__init__(name) |
| 41 | |
| 42 | def _load(self): |
| 43 | """Load the module and insert it into the parent's globals.""" |
| 44 | # Import the target module and insert it into the parent's namespace |
| 45 | module = importlib.import_module(self.__name__) |
| 46 | self._parent_module_globals[self._local_name] = module |
| 47 | |
| 48 | # Emit a warning if one was specified |
| 49 | if self._warning: |
| 50 | logging.warning(self._warning) |
| 51 | # Make sure to only warn once. |
| 52 | self._warning = None |
| 53 | |
| 54 | # Update this object's dict so that if someone keeps a reference to the |
| 55 | # LazyLoader, lookups are efficient (__getattr__ is only called on lookups |
| 56 | # that fail). |
| 57 | self.__dict__.update(module.__dict__) |
| 58 | |
| 59 | return module |
| 60 | |
| 61 | def __getattr__(self, item): |
| 62 | module = self._load() |
no test coverage detected