Created
January 23, 2017 16:30
-
-
Save RonnyPfannschmidt/f7051504cde67689b5ba10b1745aedaa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import attr | |
| import importlib | |
| from operator import attrgetter | |
| @attr.s | |
| class DefferedImport(object): | |
| module = attr.ib() | |
| attribute = attr.ib(default=None) | |
| def __get__(self, instance, owner): | |
| module = importlib.import_module(self.module) | |
| if self.attribute is None: | |
| return module | |
| else: | |
| return getattr(module, self.attribute) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment