diff --git a/src/pydase/utils/helpers.py b/src/pydase/utils/helpers.py index cdfb852..9b45f5d 100644 --- a/src/pydase/utils/helpers.py +++ b/src/pydase/utils/helpers.py @@ -170,7 +170,9 @@ def get_data_service_class_reference() -> Any: def is_property_attribute(target_obj: Any, access_path: str) -> bool: path_parts = parse_full_access_path(access_path) target_obj = get_object_by_path_parts(target_obj, path_parts[:-1]) - # TODO: check if target_obj is dict or list + + # don't have to check if target_obj is dict or list as their content cannot be + # properties -> always return False then return isinstance(getattr(type(target_obj), path_parts[-1], None), property) diff --git a/tests/utils/test_helpers.py b/tests/utils/test_helpers.py index 30e8c8d..e769716 100644 --- a/tests/utils/test_helpers.py +++ b/tests/utils/test_helpers.py @@ -108,13 +108,29 @@ def test_get_object_by_path_parts(path_parts: list[str], expected: Any) -> None: ("my_property", True), ("my_method", False), ("non_existent_attr", False), + ("nested_class_instance", False), + ("nested_class_instance.my_property", True), + ("list_attr", False), + ("list_attr[0]", False), + ("list_attr[0].my_property", True), + ("dict_attr", False), + ("dict_attr['foo']", False), + ("dict_attr['foo'].my_property", True), ], ) def test_is_property_attribute(attr_name: str, expected: bool) -> None: + class NestedClass: + @property + def my_property(self) -> str: + return "I'm a nested property" + # Test Suite class DummyClass: def __init__(self) -> None: self.regular_attribute = "I'm just an attribute" + self.nested_class_instance = NestedClass() + self.list_attr = [NestedClass()] + self.dict_attr = {"foo": NestedClass()} @property def my_property(self) -> str: