From 4d8db2121d7533fc3a92963d693e4b1209aa15b2 Mon Sep 17 00:00:00 2001 From: PythonFZ Date: Mon, 16 Dec 2024 09:05:33 +0100 Subject: [PATCH] add __len__ --- tests/test_add_connections.py | 1 + znflow/base.py | 3 +++ 2 files changed, 4 insertions(+) diff --git a/tests/test_add_connections.py b/tests/test_add_connections.py index 454bf5d..5fa8f7f 100644 --- a/tests/test_add_connections.py +++ b/tests/test_add_connections.py @@ -44,6 +44,7 @@ def test_AddLists(use_graph): outs = AddOne(lst1.outs + lst2.outs) assert isinstance(outs.value, CombinedConnections) + assert len(outs.value) == 2 assert len(outs.value.connections) == 2 assert outs.value.connections[0].instance is lst1 assert outs.value.connections[0].attribute == "outs" diff --git a/znflow/base.py b/znflow/base.py index d69446d..80e83f4 100644 --- a/znflow/base.py +++ b/znflow/base.py @@ -331,6 +331,9 @@ def __radd__(self, other): def __getitem__(self, item): return dataclasses.replace(self, item=item) + def __len__(self) -> int: + return len(self.connections) + def __iter__(self): raise TypeError(f"Can not iterate over {self}.")