|
2 | 2 | from typing import Type, Dict, Union
|
3 | 3 |
|
4 | 4 | import logging
|
5 |
| -import inspect |
6 | 5 | from _balder.vdevice import VDevice
|
7 | 6 | from _balder.feature import Feature
|
8 | 7 | from _balder.controllers.base_device_controller import BaseDeviceController
|
9 |
| -from _balder.exceptions import DeviceScopeError, VDeviceResolvingError |
| 8 | +from _balder.exceptions import VDeviceResolvingError |
10 | 9 |
|
11 | 10 | logger = logging.getLogger(__file__)
|
12 | 11 |
|
@@ -69,27 +68,7 @@ def get_outer_class(self) -> Union[Type[Feature], None]:
|
69 | 68 | """
|
70 | 69 | This method delivers the outer class of this device. In Balder, this has to be a :class:`Feature`.
|
71 | 70 | """
|
72 |
| - |
73 |
| - if self.related_cls.__qualname__.count('.') == 0: |
74 |
| - raise DeviceScopeError("the current device class is no inner class") |
75 |
| - all_splits = self.related_cls.__qualname__.split('.') |
76 |
| - |
77 |
| - outer_class = [cur_class for cur_name, cur_class in inspect.getmembers( |
78 |
| - inspect.getmodule(self.related_cls), inspect.isclass) if cur_name == all_splits[0]][0] |
79 |
| - # only get the next outer class (not higher) |
80 |
| - for cur_class_name in all_splits[1:-1]: |
81 |
| - outer_class = getattr(outer_class, cur_class_name) |
82 |
| - # instantiate it to get the real type (not the decorator class of `@for_vdevice`) |
83 |
| - # we can instantiate it, because we do nothing in it |
84 |
| - outer_class = outer_class().__class__ |
85 |
| - |
86 |
| - all_inner_classes = [cur_inner_class for _, cur_inner_class in inspect.getmembers(outer_class, inspect.isclass)] |
87 |
| - if self.related_cls in all_inner_classes: |
88 |
| - if not issubclass(outer_class, Feature): |
89 |
| - raise TypeError(f"the found outer class is of type `{outer_class.__name__}` - this is a type which is " |
90 |
| - f"not allowed (outer class has to be a `Feature` class)") |
91 |
| - return outer_class |
92 |
| - raise RuntimeError(f"can not find the outer class of this vDevice `{self.related_cls.__qualname__}`") |
| 71 | + return getattr(self.related_cls, '_outer_balder_class', None) |
93 | 72 |
|
94 | 73 | def get_next_parent_vdevice(self) -> Union[Type[VDevice], None]:
|
95 | 74 | """
|
|
0 commit comments