From a74fb7b0fa4fa9710d07e91e95d46700e4261e5e Mon Sep 17 00:00:00 2001 From: Fabian Zills <46721498+PythonFZ@users.noreply.github.com> Date: Thu, 15 Aug 2024 08:26:26 +0200 Subject: [PATCH 1/2] update protected check --- znflow/node.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/znflow/node.py b/znflow/node.py index 052991a..015a664 100644 --- a/znflow/node.py +++ b/znflow/node.py @@ -70,7 +70,7 @@ def __new__(cls, *args, **kwargs): graph.add_node(instance, this_uuid=this_uuid) return instance - def __getattribute__(self, item): + def __getattribute__(self, item: str): if item.startswith("_"): return super().__getattribute__(item) if self._graph_ not in [empty_graph, None]: @@ -80,7 +80,7 @@ def __getattribute__(self, item): f"'{self.__class__.__name__}' object has no attribute '{item}'" ) - if item not in type(self)._protected_: + if item not in self._protected_: if self._in_construction: return super().__getattribute__(item) return Connection(instance=self, attribute=item) From a44e427cbba58e8c9d52804b9e8b732ca050c566 Mon Sep 17 00:00:00 2001 From: Fabian Zills Date: Thu, 29 Aug 2024 21:02:51 +0200 Subject: [PATCH 2/2] test protected node attributes --- tests/test_protected.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 tests/test_protected.py diff --git a/tests/test_protected.py b/tests/test_protected.py new file mode 100644 index 0000000..163ef7a --- /dev/null +++ b/tests/test_protected.py @@ -0,0 +1,15 @@ +import znflow + + +class MyNode(znflow.Node): + _protected_ = znflow.Node._protected_ + ["a"] + + a: int = 42 + b: int = 42 + + +def test_protected(): + with znflow.DiGraph(): + node = MyNode() + assert node.a == 42 + assert isinstance(node.b, znflow.Connection)