From d536189d3fd74a1c7e7d2cd87a6f53fbfb9efa0a Mon Sep 17 00:00:00 2001 From: Joachim Durchholz Date: Thu, 23 Apr 2015 00:00:01 +0200 Subject: [PATCH] Fix sympy/sympy#9326: use full symbol in evalf cache, not just symbol name Old status: evalf_symbol used just the symbol name in its cache, this would break if two symbols happened to use the same name. This fix uses the full symbol instead. // edited by skirpichev --- sympy/core/evalf.py | 4 ++-- sympy/core/tests/test_evalf.py | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/sympy/core/evalf.py b/sympy/core/evalf.py index ed19f96e83e..128a87859af 100644 --- a/sympy/core/evalf.py +++ b/sympy/core/evalf.py @@ -1175,11 +1175,11 @@ def evalf_symbol(x, prec, options): if '_cache' not in options: options['_cache'] = {} cache = options['_cache'] - cached, cached_prec = cache.get(x.name, (None, MINUS_INF)) + cached, cached_prec = cache.get(x, (None, MINUS_INF)) if cached_prec >= prec: return cached v = evalf(sympify(val), prec, options) - cache[x.name] = (v, prec) + cache[x] = (v, prec) return v evalf_table = None diff --git a/sympy/core/tests/test_evalf.py b/sympy/core/tests/test_evalf.py index aff47199361..480872c7e60 100644 --- a/sympy/core/tests/test_evalf.py +++ b/sympy/core/tests/test_evalf.py @@ -475,3 +475,11 @@ def test_issue_8853(): assert get_integer_part(S.Half, 1, {}, True) == (1, 0) assert get_integer_part(-S.Half, -1, {}, True) == (-1, 0) assert get_integer_part(-S.Half, 1, {}, True) == (0, 0) + + +def test_issue_9326(): + from sympy import Dummy + d1 = Dummy('d') + d2 = Dummy('d') + e = d1 + d2 + assert e.evalf(subs={d1: 1, d2: 2}) == 3