Solve bug with simplify and postfix string

This commit is contained in:
Lafrite 2015-06-19 11:01:13 +02:00
parent 7648460022
commit bc4bb91555
2 changed files with 6 additions and 3 deletions

View File

@ -89,8 +89,8 @@ class Expression(Explicable):
if type(exp) == str: if type(exp) == str:
expression.postfix_tokens = str2tokens(exp) expression.postfix_tokens = str2tokens(exp)
elif type(exp) == list: elif type(exp) == list:
# Bug ici quand i ne peut pas être converti en string # Ici on ne peut convertir les "+" en opérateur que s'ils sont d'arité 2.
exp_mod_op = [op.get_op(i) if (str(i) in "+-*/^" and not isOperator(i)) else i for i in exp] exp_mod_op = [op.get_op(i) if op.can_be_operator(i) else i for i in exp]
expression.postfix_tokens = flatten_list([tok.postfix_tokens if Expression.isExpression(tok) else tok for tok in exp_mod_op]) expression.postfix_tokens = flatten_list([tok.postfix_tokens if Expression.isExpression(tok) else tok for tok in exp_mod_op])
elif type(exp) == Expression: elif type(exp) == Expression:
return exp return exp

View File

@ -268,7 +268,10 @@ class op(object):
@classmethod @classmethod
def can_be_operator(cls, symbole): def can_be_operator(cls, symbole):
""" Tell if the symbole can be an operator """ """ Tell if the symbole can be an operator """
return symbole in [i[0] for i in cls._operators] if type(symbole) == str:
return symbole in [i[0] for i in cls._operators]
else:
return False
@ClassProperty @ClassProperty