diff --git a/tests/test_add_connections.py b/tests/test_add_connections.py index 5fa8f7f..9d03522 100644 --- a/tests/test_add_connections.py +++ b/tests/test_add_connections.py @@ -463,3 +463,63 @@ def test_combine_error(): znflow.combine([1, 2, 3], attribute="outs", only_getattr_on_nodes=False) assert znflow.combine([1, 2, 3], attribute="outs") == [1, 2, 3] + + +def test_append_connection(): + with znflow.DiGraph(): + a = CreateList(size=5) + b = CreateList(size=4) + + assert isinstance(a.outs, znflow.Connection) + + with pytest.raises(TypeError): + a.outs.append(b.outs) + + +def test_extend_connection(): + with znflow.DiGraph(): + a = CreateList(size=5) + b = CreateList(size=4) + + with pytest.raises(TypeError): + a.outs.extend(b.outs) + + +def test_append_function_future(): + with znflow.DiGraph(): + a = create_list(5) + b = create_list(5) + + assert isinstance(a, znflow.FunctionFuture) + + with pytest.raises(TypeError): + a.append(b) + + +def test_extend_function_future(): + with znflow.DiGraph(): + a = create_list(5) + b = create_list(5) + + with pytest.raises(TypeError): + a.extend(b) + + +def test_append_combined_connection(): + with znflow.DiGraph(): + a = create_list(5) + b = create_list(5) + + assert isinstance(a + b, znflow.CombinedConnections) + + with pytest.raises(TypeError): + a.append(a + b) + + +def test_extend_combined_connection(): + with znflow.DiGraph(): + a = create_list(5) + b = create_list(5) + + with pytest.raises(TypeError): + a.extend(a + b) diff --git a/znflow/base.py b/znflow/base.py index 80e83f4..0c72baf 100644 --- a/znflow/base.py +++ b/znflow/base.py @@ -268,6 +268,24 @@ def __iter__(self): except AttributeError: raise TypeError(f"'{self}' object is not iterable") + def extend(self, *args) -> None: + """ + Raises + ------ + TypeError + If the method is called. + """ + raise TypeError("Connections can not be extended. Use 'self += other' instead.") + + def append(self, *args) -> None: + """ + Raises + ------ + TypeError + If the method is called. + """ + raise TypeError("Connections can not be appended.") + @dataclasses.dataclass(frozen=True) class CombinedConnections: @@ -350,6 +368,26 @@ def result(self): f" only supported type is list. Please change {connection}" ) from err + def extend(self, *args) -> None: + """ + Raises + ------ + TypeError + If the method is called. + """ + raise TypeError( + "CombinedConnections can not be extended. Use 'self += other' instead." + ) + + def append(self, *args) -> None: + """ + Raises + ------ + TypeError + If the method is called. + """ + raise TypeError("CombinedConnections can not be appended.") + @dataclasses.dataclass class FunctionFuture(NodeBaseMixin): @@ -436,3 +474,23 @@ def __iter__(self): return resolve(self).__iter__() except AttributeError: raise TypeError(f"'{self}' object is not iterable") + + def extend(self, *args) -> None: + """ + Raises + ------ + TypeError + If the method is called. + """ + raise TypeError( + "FunctionFuture can not be extended. Use 'self += other' instead." + ) + + def append(self, *args) -> None: + """ + Raises + ------ + TypeError + If the method is called. + """ + raise TypeError("FunctionFuture can not be appended.")