Skip to content

Commit

Permalink
raise error on append/extend
Browse files Browse the repository at this point in the history
  • Loading branch information
PythonFZ committed Dec 16, 2024
1 parent 4d8db21 commit 65631fe
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
36 changes: 36 additions & 0 deletions tests/test_add_connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,3 +463,39 @@ 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 = create_list(5)
b = create_list(5)

with pytest.raises(TypeError):
a.append(b)


def test_extend_connection():
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)

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)
38 changes: 38 additions & 0 deletions znflow/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 65631fe

Please sign in to comment.