From 3d2de7109bb39b33246fad01c1a4570019515e08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mose=20M=C3=BCller?= Date: Wed, 6 Dec 2023 09:11:14 +0100 Subject: [PATCH 1/3] removes warning if setting private attributes (should work now) --- src/pydase/data_service/data_service.py | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/pydase/data_service/data_service.py b/src/pydase/data_service/data_service.py index 763b2f7..42519eb 100644 --- a/src/pydase/data_service/data_service.py +++ b/src/pydase/data_service/data_service.py @@ -67,9 +67,6 @@ class DataService(rpyc.Service, AbstractDataService): # Check and warn for unexpected type changes in attributes self._warn_on_type_change(__name, __value) - # Warn if setting private attributes - self._warn_on_private_attr_set(__name) - # every class defined by the user should inherit from DataService if it is # assigned to a public attribute if not __name.startswith("_"): @@ -103,15 +100,6 @@ class DataService(rpyc.Service, AbstractDataService): ) ) - def _warn_on_private_attr_set(self, attr_name: str) -> None: - if attr_name.startswith(f"_{self.__class__.__name__}__"): - logger.warning( - "Warning: You should not set private but rather protected attributes! " - "Use %s instead of %s.", - attr_name.replace(f"_{self.__class__.__name__}__", "_"), - attr_name.replace(f"_{self.__class__.__name__}__", "__"), - ) - def __check_instance_classes(self) -> None: for attr_name, attr_value in get_class_and_instance_attributes(self).items(): # every class defined by the user should inherit from DataService if it is From e3367efda1dc93e47d72bc97b96e458b56b0912d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mose=20M=C3=BCller?= Date: Wed, 6 Dec 2023 09:12:00 +0100 Subject: [PATCH 2/3] removes corresponding test --- tests/utils/test_warnings.py | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/tests/utils/test_warnings.py b/tests/utils/test_warnings.py index 0abca37..01fc6ae 100644 --- a/tests/utils/test_warnings.py +++ b/tests/utils/test_warnings.py @@ -34,20 +34,6 @@ def test_instance_attr_inheritance_warning(caplog: LogCaptureFixture) -> None: ) in caplog.text -def test_private_attribute_warning(caplog: LogCaptureFixture) -> None: - class ServiceClass(DataService): - def __init__(self) -> None: - super().__init__() - self.__something = "" - - ServiceClass() - - assert ( - " Warning: You should not set private but rather protected attributes! Use " - "_something instead of __something." in caplog.text - ) - - def test_protected_attribute_warning(caplog: LogCaptureFixture) -> None: class SubClass: name = "Hello" From f70ac05df6d48325c6238624117b037c5745b63f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mose=20M=C3=BCller?= Date: Wed, 6 Dec 2023 09:16:02 +0100 Subject: [PATCH 3/3] ruff does not check tests anymore --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 5e03ccf..f9d5718 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -82,7 +82,7 @@ ignore = [ "PERF203", # try-except-in-loop ] extend-exclude = [ - "docs", "frontend" + "docs", "frontend", "tests" ] [tool.ruff.lint.mccabe]