Change binop to init value if possible

This commit is contained in:
Nuno Campos
2023-11-14 12:38:17 +00:00
parent f96ebb3357
commit cec6ba4963
2 changed files with 6 additions and 4 deletions
+4
View File
@@ -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]:
+2 -4
View File
@@ -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