Skip to content

Commit

Permalink
update protected check (#103)
Browse files Browse the repository at this point in the history
* update protected check

* test protected node attributes
  • Loading branch information
PythonFZ authored Aug 29, 2024
1 parent fb8eeb5 commit 23ccf4f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
15 changes: 15 additions & 0 deletions tests/test_protected.py
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 2 additions & 2 deletions znflow/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand All @@ -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)
Expand Down

0 comments on commit 23ccf4f

Please sign in to comment.