Expression can create fake in with simplify and simplified methods
This commit is contained in:
parent
981c8db0e5
commit
f6739f8c7c
@ -57,8 +57,22 @@ class Expression(object):
|
|||||||
raise ValueError("Can't build Expression with {} object".format(type(exp)))
|
raise ValueError("Can't build Expression with {} object".format(type(exp)))
|
||||||
|
|
||||||
if len(expression.postfix_tokens) == 1:
|
if len(expression.postfix_tokens) == 1:
|
||||||
|
token = expression.postfix_tokens[0]
|
||||||
|
if hasattr(token, 'simplify'):
|
||||||
return expression.postfix_tokens[0]
|
return expression.postfix_tokens[0]
|
||||||
|
|
||||||
|
elif type(token) == int:
|
||||||
|
# On crée un faux int en ajoutant la méthode simplify et simplified et la caractérisique isNumber
|
||||||
|
simplify = lambda x:[x]
|
||||||
|
simplified = lambda x:x
|
||||||
|
is_number = True
|
||||||
|
methods_attr = {'simplify':simplify, 'simplified':simplified, 'isNumber': is_number}
|
||||||
|
fake_token = type('fake_obj', (int,), methods_attr)(token)
|
||||||
|
return fake_token
|
||||||
|
|
||||||
|
else:
|
||||||
|
raise ValueError("Unknow type in Expression: {}".format(type(token)))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
expression._isExpression = 1
|
expression._isExpression = 1
|
||||||
return expression
|
return expression
|
||||||
|
Loading…
Reference in New Issue
Block a user