Skip to content
Snippets Groups Projects

Misc. fixes

Merged Ivar Härnqvist requested to merge misc-fixes into develop
1 unresolved thread
2 files
+ 35
35
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 27
27
@@ -35,7 +35,7 @@ class Constant(AbstractOperation):
self._output_ports = [OutputPort(0, self)]
self._parameters["value"] = value
def evaluate(self) -> Any:
    • What is the reason for removing "-> Any"?

      • It is superfluous since Any is the default return type annotation. In most cases, it would have made sense to keep it anyway for clarity, but in this case I believe it makes the user code cleaner if they don't have to add "Any" to everything since the signature for the evaluate method is completely generic (generic number of arguments, generic types of arguments and generic return type).

        In other words, I would rather have the user manual say something like "overload evaluate by writing def evaluate(a, b): return a + b" instead of "overload evaluate by writing def evaluate(a: Any, b: Any) -> Any: return a + b", since I believe the latter would only be more confusing.

        Edited by Ivar Härnqvist
      • If we don't type "Any" then there is no clear way to distinguish if the type is meant to be "Any" or if the developer forgot the typing, which I am sure will happen many times in this project considering that we are 8 developers. Don't you agree?

        Also, don't we require 2 approvals to merge to develop? I can only see that Kevin approved this. You also merged the branch before waiting for a response on the comment / it being resolved which is not the type of code reviews that we want to have. I know this is a very minor issue but there are good reasons to keep these practices in place.

      • Please register or sign in to reply
Please register or sign in to reply
def evaluate(self):
return self.param("value")
@property
@@ -59,7 +59,7 @@ class Addition(AbstractOperation):
if source2 is not None:
self._input_ports[1].connect_to_port(source2)
def evaluate(self, a, b) -> Any:
def evaluate(self, a, b):
return a + b
@property
@@ -82,11 +82,11 @@ class Subtraction(AbstractOperation):
if source2 is not None:
self._input_ports[1].connect_to_port(source2)
def evaluate(self, a, b) -> Any:
def evaluate(self, a, b):
return a - b
@property
def type_name(self) -> GraphIDType:
def type_name(self) -> TypeName:
return "sub"
@@ -105,11 +105,11 @@ class Multiplication(AbstractOperation):
if source2 is not None:
self._input_ports[1].connect_to_port(source2)
def evaluate(self, a, b) -> Any:
def evaluate(self, a, b):
return a * b
@property
def type_name(self) -> GraphIDType:
def type_name(self) -> TypeName:
return "mul"
@@ -128,11 +128,11 @@ class Division(AbstractOperation):
if source2 is not None:
self._input_ports[1].connect_to_port(source2)
def evaluate(self, a, b) -> Any:
def evaluate(self, a, b):
return a / b
@property
def type_name(self) -> GraphIDType:
def type_name(self) -> TypeName:
return "div"
@@ -150,11 +150,11 @@ class SquareRoot(AbstractOperation):
self._input_ports[0].connect_to_port(source1)
def evaluate(self, a) -> Any:
def evaluate(self, a):
return sqrt((complex)(a))
@property
def type_name(self) -> GraphIDType:
def type_name(self) -> TypeName:
return "sqrt"
@@ -172,11 +172,11 @@ class ComplexConjugate(AbstractOperation):
self._input_ports[0].connect_to_port(source1)
def evaluate(self, a) -> Any:
def evaluate(self, a):
return conjugate(a)
@property
def type_name(self) -> GraphIDType:
def type_name(self) -> TypeName:
return "conj"
@@ -195,13 +195,13 @@ class Max(AbstractOperation):
if source2 is not None:
self._input_ports[1].connect_to_port(source2)
def evaluate(self, a, b) -> Any:
def evaluate(self, a, b):
assert not isinstance(a, complex) and not isinstance(b, complex), \
("core_operation.Max does not support complex numbers.")
("core_operations.Max does not support complex numbers.")
return a if a > b else b
@property
def type_name(self) -> GraphIDType:
def type_name(self) -> TypeName:
return "max"
@@ -220,13 +220,13 @@ class Min(AbstractOperation):
if source2 is not None:
self._input_ports[1].connect_to_port(source2)
def evaluate(self, a, b) -> Any:
def evaluate(self, a, b):
assert not isinstance(a, complex) and not isinstance(b, complex), \
("core_operation.Min does not support complex numbers.")
("core_operations.Min does not support complex numbers.")
return a if a < b else b
@property
def type_name(self) -> GraphIDType:
def type_name(self) -> TypeName:
return "min"
@@ -244,11 +244,11 @@ class Absolute(AbstractOperation):
self._input_ports[0].connect_to_port(source1)
def evaluate(self, a) -> Any:
def evaluate(self, a):
return np_abs(a)
@property
def type_name(self) -> GraphIDType:
def type_name(self) -> TypeName:
return "abs"
@@ -266,7 +266,7 @@ class ConstantMultiplication(AbstractOperation):
if source1 is not None:
self._input_ports[0].connect_to_port(source1)
def evaluate(self, a) -> Any:
def evaluate(self, a):
return a * self.param("coefficient")
@property
@@ -288,11 +288,11 @@ class ConstantAddition(AbstractOperation):
if source1 is not None:
self._input_ports[0].connect_to_port(source1)
def evaluate(self, a) -> Any:
def evaluate(self, a):
return a + self.param("coefficient")
@property
def type_name(self) -> GraphIDType:
def type_name(self) -> TypeName:
return "cadd"
@@ -310,11 +310,11 @@ class ConstantSubtraction(AbstractOperation):
if source1 is not None:
self._input_ports[0].connect_to_port(source1)
def evaluate(self, a) -> Any:
def evaluate(self, a):
return a - self.param("coefficient")
@property
def type_name(self) -> GraphIDType:
def type_name(self) -> TypeName:
return "csub"
@@ -332,9 +332,9 @@ class ConstantDivision(AbstractOperation):
if source1 is not None:
self._input_ports[0].connect_to_port(source1)
def evaluate(self, a) -> Any:
def evaluate(self, a):
return a / self.param("coefficient")
@property
def type_name(self) -> GraphIDType:
def type_name(self) -> TypeName:
return "cdiv"
Loading