reset priorities

This commit is contained in:
Lafrite 2015-03-07 18:23:10 +01:00
parent 374f0bc07e
commit e031f9b903
1 changed files with 10 additions and 5 deletions

View File

@ -139,10 +139,15 @@ class Operator(str):
return ans return ans
def add_parenthesis(self, op): def add_parenthesis(self, op):
""" Add parenthesis if necessary """ """ Add parenthesis if necessary
>>> from pymath.polynom import Polynom
>>> P = Polynom([1,2,3])
"""
try: try:
if op.mainOp.priority < self.priority: if op.mainOp.priority < self.priority:
op = flatten_list(["("] + [op] + [")"]) op = flatten_list(["(", op, ")"])
except AttributeError: except AttributeError:
# op has not the attribute priority # op has not the attribute priority
try: try:
@ -293,7 +298,7 @@ class op(object):
caract = { caract = {
"operator" : "-", \ "operator" : "-", \
"name" : "sub",\ "name" : "sub",\
"priority" : 1, \ "priority" : 2, \
"arity" : 2, \ "arity" : 2, \
"actions" : ("__sub__","__rsub__"), \ "actions" : ("__sub__","__rsub__"), \
"txt" : "{op1} - {op2}",\ "txt" : "{op1} - {op2}",\
@ -336,7 +341,7 @@ class op(object):
caract = { caract = {
"operator" : "-", \ "operator" : "-", \
"name" : "sub1",\ "name" : "sub1",\
"priority" : 2, \ "priority" : 3, \
"arity" : 1, \ "arity" : 1, \
"actions" : "__neg__",\ "actions" : "__neg__",\
"txt" : "- {op1}",\ "txt" : "- {op1}",\
@ -461,7 +466,7 @@ class op(object):
caract = { caract = {
"operator" : "^", \ "operator" : "^", \
"name" : "pw",\ "name" : "pw",\
"priority" : 5, \ "priority" : 6, \
"arity" : 2, \ "arity" : 2, \
"actions" : ("__pow__",""), \ "actions" : ("__pow__",""), \
"txt" : "{op1} ^ {op2}",\ "txt" : "{op1} ^ {op2}",\