Skip to content

Commit

Permalink
Add comment explaining embedded constant
Browse files Browse the repository at this point in the history
  • Loading branch information
jsiirola committed Feb 11, 2025
1 parent 590dcae commit 975fbd7
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pyomo/core/expr/visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1674,6 +1674,12 @@ def visit(self, node, values):
for i, (val, arg) in enumerate(zip(values, node.args)):
arg_prec = getattr(arg, 'PRECEDENCE', None)
if arg_prec is None:
# This embedded constant (4) is evil, but to actually
# import the NegationExpression.PRECEDENCE from
# numeric_expr would create a circular dependency.
#
# FIXME: rework the dependencies between
# numeric_expr and visitor
if val[0] == '-' and node_prec < 4:
values[i] = f"({val})"
else:
Expand Down Expand Up @@ -1703,7 +1709,7 @@ def visiting_potential_leaf(self, node):
Return True if the node is not expanded.
"""
if node is None:
return True, None
return True, 'Undefined'

if node.__class__ in native_numeric_types:
return True, str(node)
Expand Down

0 comments on commit 975fbd7

Please sign in to comment.