From 975fbd712b4d00462d2752599a3d15eaf05b7f8a Mon Sep 17 00:00:00 2001 From: John Siirola Date: Tue, 11 Feb 2025 08:19:12 -0700 Subject: [PATCH] Add comment explaining embedded constant --- pyomo/core/expr/visitor.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pyomo/core/expr/visitor.py b/pyomo/core/expr/visitor.py index 5ab7a6e8ca2..98da9fb963e 100644 --- a/pyomo/core/expr/visitor.py +++ b/pyomo/core/expr/visitor.py @@ -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: @@ -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)