| 61 | # load_once() the first time it's needed. The class is nested so we can close |
| 62 | # over load_once() and avoid polluting the module's attrs with our own state. |
| 63 | class LazyModule(types.ModuleType): |
| 64 | def __getattr__(self, attr_name): |
| 65 | return getattr(load_once(self), attr_name) |
| 66 | |
| 67 | def __dir__(self): |
| 68 | return dir(load_once(self)) |
| 69 | |
| 70 | def __repr__(self): |
| 71 | if load_once.loaded: |
| 72 | return "<%r via LazyModule (loaded)>" % load_once(self) |
| 73 | return ( |
| 74 | "<module %r via LazyModule (not yet loaded)>" |
| 75 | % self.__name__ |
| 76 | ) |
| 77 | |
| 78 | return LazyModule(name) |
| 79 |
no outgoing calls
no test coverage detected
searching dependent graphs…