From 537a2035cc1dafc7896879008ae240befd58dd8f Mon Sep 17 00:00:00 2001 From: rocky Date: Fri, 24 Jan 2025 10:00:12 -0500 Subject: [PATCH] Use context-stripped names in str(Expression) --- mathics/core/expression.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/mathics/core/expression.py b/mathics/core/expression.py index 80de31c6a..bc37b9519 100644 --- a/mathics/core/expression.py +++ b/mathics/core/expression.py @@ -317,7 +317,7 @@ def __repr__(self) -> str: def __str__(self) -> str: return "%s[%s]" % ( - str(self.head), + self.get_head_name(short=True), ", ".join([str(element) for element in self.elements]), ) @@ -765,8 +765,12 @@ def get_elements(self) -> Sequence[BaseElement]: def get_head(self): return self._head - def get_head_name(self): - return self._head.name if isinstance(self._head, Symbol) else "" + def get_head_name(self, short=False) -> str: + """Returns an Expression's Head[] as a string. If + `short` is True, we remove leading context paths. + """ + head_name = self._head.name if isinstance(self._head, Symbol) else "" + return head_name.split("`")[-1] if short else head_name def get_lookup_name(self) -> str: """