From 2abee1095a4c311be4830392f100fe27ce453a87 Mon Sep 17 00:00:00 2001 From: Benjamin Bertrand Date: Sat, 19 Mar 2016 15:30:52 +0300 Subject: [PATCH] Replace is_same_step by __eq__ for Step --- pymath/calculus/decorators.py | 14 -------------- pymath/calculus/explicable.py | 4 ++-- pymath/calculus/step.py | 8 ++++++++ 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/pymath/calculus/decorators.py b/pymath/calculus/decorators.py index d533968..2773582 100644 --- a/pymath/calculus/decorators.py +++ b/pymath/calculus/decorators.py @@ -3,20 +3,6 @@ from functools import wraps -def is_same_step(new, old): - """Return whether the new step is the same than old step - """ - try: - if new.replace(" ", "") == old.replace(" ", ""): - return True - else: - return False - except AttributeError: - if new == old: - return True - else: - return False - def no_repetition(equals=lambda x,y: x == y): """ Remove yield values which has already been yield diff --git a/pymath/calculus/explicable.py b/pymath/calculus/explicable.py index 0a54f1c..9e46d74 100644 --- a/pymath/calculus/explicable.py +++ b/pymath/calculus/explicable.py @@ -5,7 +5,7 @@ from .renderable import Renderable from .step import Step from decimal import Decimal from .generic import transpose_fill -from .decorators import is_same_step, no_repetition +from .decorators import no_repetition class Explicable(Renderable): @@ -57,7 +57,7 @@ class Explicable(Renderable): """ Generator which yield itself rendered """ yield self.STR_RENDER(self.postfix_tokens) - @no_repetition(is_same_step) + @no_repetition() def history_generator(self): r""" Generator for rendered steps which leed to itself diff --git a/pymath/calculus/step.py b/pymath/calculus/step.py index da97089..bf6aa05 100644 --- a/pymath/calculus/step.py +++ b/pymath/calculus/step.py @@ -69,6 +69,14 @@ class Step(Renderable): exp )) + def __eq__(self, other): + try: + if self.postfix_tokens == other.postfix_tokens: + return True + except AttributeError: + return False + + return False # ----------------------------- # Reglages pour 'vim'