From 8881a15c9bcf7ff6a63282be773a44df2565c5dc Mon Sep 17 00:00:00 2001 From: Lafrite Date: Sun, 28 Dec 2014 10:28:31 +0100 Subject: [PATCH] Adapt Polynom with Expression.tmp_render env --- pymath/polynom.py | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/pymath/polynom.py b/pymath/polynom.py index c2efb91..6a8f10a 100644 --- a/pymath/polynom.py +++ b/pymath/polynom.py @@ -291,19 +291,15 @@ class Polynom(object): # On converti en Expression coef_exp = Expression(postfix_add) - old_render = Expression.get_render() - Expression.set_render(lambda _,x:Expression(x)) - coef_steps = list(coef_exp.simplify()) - Expression.set_render(old_render) + with Expression.tmp_render(): + coef_steps = list(coef_exp.simplify()) #print('\t 1.coef_steps -> ', coef_steps) elif type(coef) == Expression: - old_render = Expression.get_render() - Expression.set_render(lambda _,x:Expression(x)) - coef_steps = list(coef.simplify()) - Expression.set_render(old_render) + with Expression.tmp_render(): + coef_steps = list(coef.simplify()) #print('\t 2.coef_steps -> ', coef_steps) @@ -524,12 +520,12 @@ def test(p,q): if __name__ == '__main__': #from .fraction import Fraction - Expression.set_render(txt) - p = Polynom([10, -5]) - q = Polynom([3, -9]) - print(p-q) - for i in p-q: - print(i) + with Expression.tmp_render(txt): + p = Polynom([10, -5]) + q = Polynom([3, -9]) + print(p-q) + for i in p-q: + print(i) import doctest