Skip to content

Commit

Permalink
Merge pull request sympy#22548 from ayushbisht2001/assumptions_bug
Browse files Browse the repository at this point in the history
work around for inconsistent-assumptions error
  • Loading branch information
oscarbenjamin authored Nov 27, 2021
2 parents 19ca4f0 + bd8d20b commit 39f2a45
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions sympy/core/assumptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@
"""

from .facts import FactRules, FactKB
from .facts import FactRules, FactKB, InconsistentAssumptions
from .core import BasicMeta
from .sympify import sympify

Expand Down Expand Up @@ -515,7 +515,25 @@ def _ask(fact, obj):

# Store None into the assumptions so that recursive attempts at
# evaluating the same fact don't trigger infinite recursion.
assumptions._tell(fact, None)
#
# Potentially in a multithreaded context it is possible that the
# assumptions query for fact was already resolved in another thread. If
# that happens and the query was resolved as True or False then
# assumptions._tell will raise InconsistentAssumptions because of the
# attempt to replace True/False with None. In that case it should be safe
# to catch the exception and return the result that was computed in the
# other thread.
#
# XXX: Ideally this call to assumptions._tell would be removed. Its purpose
# is to guard against infinite recursion if a query for one fact attempts
# to evaluate a related fact for the same object. However really this is
# just masking bugs because a query for a fact about obj should only query
# the properties of obj.args and not obj itself. This is not easy to change
# though because it requires fixing all of the buggy _eval_is_* handlers.
try:
assumptions._tell(fact, None)
except InconsistentAssumptions:
return assumptions[fact]

# First try the assumption evaluation function if it exists
try:
Expand Down

0 comments on commit 39f2a45

Please sign in to comment.