Skip to content

Commit

Permalink
Don't use Expr.__str__ for general use #139
Browse files Browse the repository at this point in the history
  • Loading branch information
mph- committed Sep 15, 2024
1 parent 748aefd commit 249b745
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
17 changes: 10 additions & 7 deletions lcapy/expr.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,16 @@ def _pexpr(self):
if not hasattr(self, 'expr'):
return self

if state.show_units:
if state.canonical_units:
return self.expr_with_canonical_units
else:
return self.expr_with_units
else:
return self.expr
try:
if state.show_units:
if state.canonical_units:
return self.expr_with_canonical_units
else:
return self.expr_with_units
except AttributeError:
pass

return self.expr

def __repr__(self):
"""This is called by repr(expr). It is used, e.g., when printing
Expand Down
7 changes: 7 additions & 0 deletions lcapy/mnacpts.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,13 @@ def _expand(self):
def _arg_format(self, value):
"""Place value string inside curly braces if it contains a delimiter."""

# Don't use Expr.__str__ since this will add units
# if show_units enabled.
try:
value = value.sympy
except AttributeError:
pass

string = str(value)

if string.startswith('{'):
Expand Down

0 comments on commit 249b745

Please sign in to comment.