From cec6ba4963d8746c577c3e68d395ef23bc725c4f Mon Sep 17 00:00:00 2001 From: Nuno Campos Date: Tue, 14 Nov 2023 12:38:17 +0000 Subject: [PATCH] Change binop to init value if possible --- permchain/channels/binop.py | 4 ++++ tests/test_channels.py | 6 ++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/permchain/channels/binop.py b/permchain/channels/binop.py index 322f99c3e..8cbe092cc 100644 --- a/permchain/channels/binop.py +++ b/permchain/channels/binop.py @@ -19,6 +19,10 @@ class BinaryOperatorAggregate(Generic[Value], BaseChannel[Value, Value, Value]): def __init__(self, typ: Type[Value], operator: Callable[[Value, Value], Value]): self.typ = typ self.operator = operator + try: + self.value = typ() + except Exception: + pass @property def ValueType(self) -> Type[Value]: diff --git a/tests/test_channels.py b/tests/test_channels.py index 104206c10..e183ece2e 100644 --- a/tests/test_channels.py +++ b/tests/test_channels.py @@ -204,8 +204,7 @@ def test_binop() -> None: assert channel.ValueType is int assert channel.UpdateType is int - with pytest.raises(EmptyChannelError): - channel.get() + assert channel.get() == 0 channel.update([1, 2, 3]) assert channel.get() == 6 @@ -221,8 +220,7 @@ async def test_binop_async() -> None: assert channel.ValueType is int assert channel.UpdateType is int - with pytest.raises(EmptyChannelError): - channel.get() + assert channel.get() == 0 channel.update([1, 2, 3]) assert channel.get() == 6