From 77ef6a9e6b851463249ac9c0d20fc3c6e968a317 Mon Sep 17 00:00:00 2001 From: Juan Mauricio Matera Date: Mon, 12 Oct 2026 22:18:04 -0300 Subject: [PATCH] fix __repr__ methods for uninitialized BoxExpressions --- mathics/builtin/box/layout.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/mathics/builtin/box/layout.py b/mathics/builtin/box/layout.py index 3c35a86c80..c6a34d0004 100644 --- a/mathics/builtin/box/layout.py +++ b/mathics/builtin/box/layout.py @@ -278,9 +278,11 @@ class InterpretationBox(BoxExpression): summary_text = "box associated to an input expression" def __repr__(self): - result = "InterpretationBox\n " + repr(self.inner_box) - result += f"\n {self.box_options}" - return result + if hasattr(self, "inner_box"): + result = "InterpretationBox\n " + repr(self.inner_box) + result += f"\n {self.box_options}" + return result + return "Uninitialized {type(self)} at {id(self)}." def init(self, *expr, **options): self.inner_box = expr[0] @@ -400,7 +402,9 @@ def __init__(self, *args, **kwargs): self.inside_list = False def __repr__(self): - return f"RowBox[{self.elements[0].__repr__()}]" + if hasattr(self, "items"): + return f"RowBox[{self.elements[0].__repr__()}]" + return f"Uninitialized <{type(self)} at {id(self)}.>" @property def elements(self): @@ -572,7 +576,9 @@ class StyleBox(BoxExpression): summary_text = "associate boxes with styles" def __repr__(self): - return repr(self.to_expression()) + if hasattr(self, "style"): + return repr(self.to_expression()) + return f"Uninitialized {type(self)} at {id(self)}." @property def elements(self):