avoid a sideeffect in r_parenthesis

This commit is contained in:
Benjamin Bertrand 2016-03-11 18:29:05 +03:00
parent a0b014dd08
commit 9a141ec2f7
1 changed files with 5 additions and 5 deletions

View File

@ -167,7 +167,6 @@ class Operator():
""" Add parenthesis for left operand if necessary """
ans = opl
try:
# TODO: Je pige pas pourquoi quand on enlève .name ça marche plus... |lun. avril 27 19:07:24 CEST 2015
if opl.mainOp.name == "sub1":
ans = opl
elif opl.mainOp.priority < self.priority:
@ -183,17 +182,18 @@ class Operator():
def r_parenthesis(self, op, str_join=False):
""" Add parenthesis for rigth operand if necessary """
ans = op
try:
if op.mainOp.priority < self.priority:
op = flatten_list(["(", op, ")"])
ans = flatten_list(["(", ans, ")"])
except AttributeError:
# op has not the attribute priority
try:
if int(op) < 0:
op = ['(', op, ')']
if int(ans) < 0:
ans = ['(', ans, ')']
except ValueError:
pass
ans = flatten_list([op])
ans = flatten_list([ans])
if str_join:
ans = ' '.join([str(i) for i in ans])
return ans