Source: Trimesh package @ https://github.com/mikedh/trimesh/blob/master/trimesh/exceptions.py Create a dummy module which will raise an exception when attributes are accessed. For soft dependencies we want to survive failing to import but we would like to raise an appropriate e
| 17 | |
| 18 | |
| 19 | class ExceptionModule(object): |
| 20 | """ |
| 21 | Source: Trimesh package @ https://github.com/mikedh/trimesh/blob/master/trimesh/exceptions.py |
| 22 | |
| 23 | Create a dummy module which will raise an exception when attributes |
| 24 | are accessed. |
| 25 | For soft dependencies we want to survive failing to import but |
| 26 | we would like to raise an appropriate error when the functionality is |
| 27 | actually requested so the user gets an easily debuggable message. |
| 28 | """ |
| 29 | |
| 30 | def __init__(self, exc): |
| 31 | self.exc = exc |
| 32 | |
| 33 | def __getattribute__(self, *args, **kwargs): |
| 34 | # if it's asking for our class type return None |
| 35 | # this allows isinstance() checks to not re-raise |
| 36 | if args[0] == "__class__": |
| 37 | return None.__class__ |
| 38 | # otherwise raise our original exception |
| 39 | raise super(ExceptionModule, self).__getattribute__("exc") |
nothing calls this directly
no outgoing calls
no test coverage detected