From a2041fd451fafd69bcb87a815b55aa179f91c1ee Mon Sep 17 00:00:00 2001 From: Lafrite Date: Sun, 5 Apr 2015 17:04:04 +0200 Subject: [PATCH] solve issue with explain and wrong steps --- pymath/expression.py | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/pymath/expression.py b/pymath/expression.py index 08ec98b..aa83b0e 100644 --- a/pymath/expression.py +++ b/pymath/expression.py @@ -186,13 +186,31 @@ class Expression(Explicable): tmpTokenList += tokenList - steps = expand_list(tmpTokenList) + #print(repr(self)) + #print(" tmpTokenList -> ", tmpTokenList) + #steps = expand_list([i.explain() for i in tmpTokenList]) + #print("steps -> ", steps) - if len(steps[:-1]) > 0: - child_steps += [flatten_list(s) for s in steps[:-1]] + #if len(steps[:-1]) > 0: + # child_steps += [flatten_list(s) for s in steps[:-1]] - self.child = Expression(steps[-1]) - self.child.steps = child_steps + self.child = Expression(tmpTokenList) + self.child.steps = self.develop_steps(tmpTokenList) + + def develop_steps(self, tokenList): + """ From a list of tokens, it develops steps of each tokens """ + tmp_steps = [] + with Expression.tmp_render(): + for t in tokenList: + if hasattr(t, "explain"): + tmp_steps.append([i for i in t.explain()]) + else: + tmp_steps.append(t) + tmp_steps = expand_list(tmp_steps) + #print("tmp_steps -> ", tmp_steps) + steps = [Expression(s) for s in tmp_steps] + + return steps @classmethod def isExpression(self, other):