Skip to content

Commit 8c50b6f

Browse files
committed
fix(*device_controller.py): use new information from metaclass InnerDeviceManagingMetaclass in get_outer_class()
1 parent 41dd6cb commit 8c50b6f

File tree

2 files changed

+4
-43
lines changed

2 files changed

+4
-43
lines changed

src/_balder/controllers/device_controller.py

+2-20
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from _balder.scenario import Scenario
1313
from _balder.controllers.base_device_controller import BaseDeviceController
1414
from _balder.controllers.feature_controller import FeatureController
15-
from _balder.exceptions import DeviceScopeError, DeviceResolvingException, InnerFeatureResolvingError, \
15+
from _balder.exceptions import DeviceResolvingException, InnerFeatureResolvingError, \
1616
FeatureOverwritingError, MultiInheritanceError
1717
if TYPE_CHECKING:
1818
from _balder.connection import Connection
@@ -307,25 +307,7 @@ def get_outer_class(self) -> Union[Type[Scenario], Type[Setup], None]:
307307
This method delivers the outer class of the related device. This has to be a :class:`Setup` or a
308308
:class:`Scenario`.
309309
"""
310-
311-
if self.related_cls.__qualname__.count('.') == 0:
312-
raise DeviceScopeError("the current device class is no inner class")
313-
314-
if self.related_cls.__qualname__.count('.') > 1:
315-
raise DeviceScopeError("the current device class is no direct inner class (deeper than one)")
316-
317-
outer_class_name, _ = self.related_cls.__qualname__.split('.')
318-
319-
outer_class = [cur_class for cur_name, cur_class in inspect.getmembers(
320-
inspect.getmodule(self.related_cls)) if cur_name == outer_class_name][0]
321-
322-
all_inner_classes = [cur_inner_class for _, cur_inner_class in inspect.getmembers(outer_class, inspect.isclass)]
323-
if self.related_cls in all_inner_classes:
324-
if not issubclass(outer_class, Setup) and not issubclass(outer_class, Scenario):
325-
raise TypeError(
326-
f"the outer class is of the type `{outer_class.__name__}` - this is not allowed")
327-
return outer_class
328-
raise RuntimeError(f"can not find the outer class of this given device `{self.related_cls.__qualname__}`")
310+
return getattr(self.related_cls, '_outer_balder_class', None)
329311

330312
def resolve_connection_device_strings(self):
331313
"""

src/_balder/controllers/vdevice_controller.py

+2-23
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
from typing import Type, Dict, Union
33

44
import logging
5-
import inspect
65
from _balder.vdevice import VDevice
76
from _balder.feature import Feature
87
from _balder.controllers.base_device_controller import BaseDeviceController
9-
from _balder.exceptions import DeviceScopeError, VDeviceResolvingError
8+
from _balder.exceptions import VDeviceResolvingError
109

1110
logger = logging.getLogger(__file__)
1211

@@ -69,27 +68,7 @@ def get_outer_class(self) -> Union[Type[Feature], None]:
6968
"""
7069
This method delivers the outer class of this device. In Balder, this has to be a :class:`Feature`.
7170
"""
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)
9372

9473
def get_next_parent_vdevice(self) -> Union[Type[VDevice], None]:
9574
"""

0 commit comments

Comments
 (0)