From 591a1a99ad7b76b659f06c14523b75bd55519bd9 Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Thu, 9 May 2024 19:51:26 +0200 Subject: Add __str__ to NonNegative constraint --- sumofsquares/constraints.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/sumofsquares/constraints.py b/sumofsquares/constraints.py index 41f2b14..37486e1 100644 --- a/sumofsquares/constraints.py +++ b/sumofsquares/constraints.py @@ -33,7 +33,8 @@ class ArchimedeanSet(Set): polynomials: tuple[Expression] def __str__(self): - return f"{self.__class__.__qualname__}({', '.join(map(str, self.polynomials))})" + polynomials = ', '.join(map(str, self.polynomials)) + return f"{self.__class__.__qualname__}({polynomials})" @dataclassabc(frozen=True) @@ -41,6 +42,10 @@ class EqualToZero(Constraint): """ Constrain an expression to be equal to zero. """ expression: Expression + @override + def __str__(self): + return f"{self.__class__.__qualname__}: {str(self.expression)}" + @dataclassabc(frozen=True) class NonNegative(Constraint): @@ -59,7 +64,7 @@ class NonNegative(Constraint): @override def __str__(self): - s = f"{self.__class__.__qualname__} {str(self.expression)}" + s = f"{self.__class__.__qualname__}: {str(self.expression)}" if self.domain: s += f"\n\t\t over {self.domain}" return s -- cgit v1.2.1