diff --git a/pytensor/raise_op.py b/pytensor/raise_op.py index 554e8f9b4c..cf951a2527 100644 --- a/pytensor/raise_op.py +++ b/pytensor/raise_op.py @@ -48,7 +48,13 @@ def __init__(self, exc_type, msg=""): self.msg = msg def __str__(self): - return f"CheckAndRaise{{{self.exc_type}({self.msg})}}" + name = self.__class__.__name__ + exc_name = self.exc_type.__name__ + if len(self.msg) > 30: + msg = self.msg[:27] + "..." + else: + msg = self.msg + return f"{name}{{raises={exc_name}, msg='{msg}'}}" def __eq__(self, other): if type(self) is not type(other): @@ -195,7 +201,11 @@ def __init__(self, msg="PyTensor Assert failed!"): super().__init__(AssertionError, msg) def __str__(self): - return f"Assert{{msg={self.msg}}}" + if len(self.msg) > 30: + msg = self.msg[:27] + "..." + else: + msg = self.msg + return f"Assert{{msg='{msg}'}}" assert_op = Assert() diff --git a/tests/test_raise_op.py b/tests/test_raise_op.py index e41fec28aa..7d10f760d9 100644 --- a/tests/test_raise_op.py +++ b/tests/test_raise_op.py @@ -24,7 +24,7 @@ def test_CheckAndRaise_str(): check_and_raise = CheckAndRaise(CustomException, exc_msg) assert ( str(check_and_raise) - == f"CheckAndRaise{{{CustomException}(this is the exception)}}" + == f"CheckAndRaise{{raises=CustomException, msg='{exc_msg}'}}" )