From 2eb5e1ccfc4380f24c5a4e590f905e23e0bf1cab Mon Sep 17 00:00:00 2001 From: Andreas Kloeckner Date: Wed, 1 Jul 2009 14:04:24 -0400 Subject: [PATCH] Improve and simplify parenthesization of constants in stringifier. --- pymbolic/mapper/stringifier.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/pymbolic/mapper/stringifier.py b/pymbolic/mapper/stringifier.py index 754e966..b681c8e 100644 --- a/pymbolic/mapper/stringifier.py +++ b/pymbolic/mapper/stringifier.py @@ -47,11 +47,9 @@ class StringifyMapper(pymbolic.mapper.RecursiveMapper): def map_constant(self, expr, enclosing_prec): result = self.constant_mapper(expr) - if ( - (isinstance(expr, (int, float, long)) and expr < 0) - or - (isinstance(expr, complex) and expr.imag and expr.real) - ) and (enclosing_prec > PREC_SUM): + if not (result.startswith("(") and result.endswith(")")) \ + and ("-" in result or "+" in result) \ + and (enclosing_prec > PREC_SUM): return self.parenthesize(result) else: return result -- GitLab