cahnge Fake_int to Explicable_int
This commit is contained in:
parent
47d43849d0
commit
a5d84e89e3
@ -14,17 +14,17 @@ from .random_expression import RdExpression
|
||||
__all__ = ['Expression']
|
||||
|
||||
|
||||
class Fake_int(int, Explicable):
|
||||
class Explicable_int(int, Explicable):
|
||||
isNumber = True
|
||||
|
||||
def __init__(self, val):
|
||||
super(Fake_int, self).__init__(val)
|
||||
super(Explicable_int, self).__init__(val)
|
||||
self._val = val
|
||||
self.postfix_tokens = [self]
|
||||
self.steps = []
|
||||
|
||||
def simplify(self):
|
||||
return Fake_int(self._val)
|
||||
return Explicable_int(self._val)
|
||||
|
||||
|
||||
class Expression(Explicable):
|
||||
@ -94,12 +94,14 @@ class Expression(Explicable):
|
||||
expression.postfix_tokens = str2tokens(exp)
|
||||
|
||||
elif isinstance(exp, list):
|
||||
# Ici on ne peut convertir les "+" en opérateur que s'ils sont
|
||||
# Ici on ne peut convertir les "+-*/..." en opérateur que s'ils sont
|
||||
# d'arité 2.
|
||||
exp_mod_op = [
|
||||
op.get_op(i) if op.can_be_operator(i) else i for i in exp]
|
||||
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])
|
||||
[tok.postfix_tokens if Expression.isExpression(tok) else tok for tok in exp_mod_op]
|
||||
)
|
||||
|
||||
elif isinstance(exp, Expression):
|
||||
return exp
|
||||
@ -110,31 +112,23 @@ class Expression(Explicable):
|
||||
else:
|
||||
raise ValueError(
|
||||
"Can't build Expression with {} object".format(
|
||||
type(exp)))
|
||||
type(exp)
|
||||
)
|
||||
)
|
||||
|
||||
if len(expression.postfix_tokens) == 1:
|
||||
token = expression.postfix_tokens[0]
|
||||
|
||||
if isinstance(token, Fake_int) or isinstance(token, int):
|
||||
return Fake_int(token)
|
||||
if isinstance(token, Explicable_int) or isinstance(token, int):
|
||||
return Explicable_int(token)
|
||||
|
||||
elif hasattr(token, 'simplify') and hasattr(token, 'explain'):
|
||||
ans = expression.postfix_tokens[0]
|
||||
return ans
|
||||
|
||||
elif isinstance(token, str):
|
||||
# TODO: Pourquoi ne pas créer directement un polynom ici? |jeu. févr. 26 18:59:24 CET 2015
|
||||
# On crée un faux str en ajoutant la méthode simplify et
|
||||
# simplified et la caractérisique isNumber
|
||||
simplify = lambda x: [x]
|
||||
is_polynom = True
|
||||
methods_attr = {
|
||||
'simplify': simplify,
|
||||
'_isPolynom': is_polynom,
|
||||
'postfix_tokens': [token]}
|
||||
fake_token = type(
|
||||
'fake_str', (str, Explicable, ), methods_attr)(token)
|
||||
return fake_token
|
||||
from .polynom import Polynom
|
||||
return Polynom([0,1], letter = token)
|
||||
|
||||
else:
|
||||
raise ValueError(
|
||||
|
Loading…
Reference in New Issue
Block a user