Repository: sympy/sympy
File: sympy/core/expr.py (Python)

Code before:
                    if isinstance(C, Limit):
                        raise NotImplementedError("Could not compute limit")
            return C

        if a == b:
            return S.Zero

        A = _eval_endpoint(left=True)
        if A is S.NaN:
            return A

        B = _eval_endpoint(left=False)

        if (a and b) is None:
            return B - A

        value = B - A

        # Catch undefined forms like oo - oo or oo * symbolic
        if isinstance(value, Add) and any(arg.is_infinite for arg in value.args):
            if any(a.is_infinite for a in value.args) and any(a.has(x) for a in value.args):
                return S.NaN

        if isinstance(value, Mul) and any(arg.is_infinite for arg in value.args):
            if any(arg.has(x) for arg in value.args if arg != S.Infinity and arg != S.NegativeInfinity):
                return S.NaN

        if a.is_comparable and b.is_comparable:
            if a < b:
                domain = Interval(a, b)
            else:
                domain = Interval(b, a)
            # check the singularities of self within the interval
            # if singularities is a ConditionSet (not iterable), catch the exception and pass
            singularities = solveset(self.cancel().as_numer_denom()[1], x,
                domain=domain)
            for logterm in self.atoms(log):
                singularities = singularities | solveset(logterm.args[0], x,
                    domain=domain)
            try:
                for s in singularities:
                    if value is S.NaN:
                        # no need to keep adding, it will stay NaN
                        break
                    if not s.is_comparable:
                        continue
                    if (a < s) == (s < b) == True:
                        value += -limit(self, x, s, "+") + limit(self, x, s, "-")
                    elif (b < s) == (s < a) == True:
                        value += limit(self, x, s, "+") - limit(self, x, s, "-")
            except TypeError:

Review comment (suggestion):
I don't understand why you have added this. Why not just remove it?

It doesn't really fix anything in a robust way.

Code after:
                    if isinstance(C, Limit):
                        raise NotImplementedError("Could not compute limit")
            return C

        if a == b:
            return S.Zero

        A = _eval_endpoint(left=True)
        if A is S.NaN:
            return A

        B = _eval_endpoint(left=False)

        if (a and b) is None:
            return B - A

        value = B - A

        if a.is_comparable and b.is_comparable:
            if a < b:
                domain = Interval(a, b)
            else:
                domain = Interval(b, a)
            # check the singularities of self within the interval
            # if singularities is a ConditionSet (not iterable), catch the exception and pass
            singularities = solveset(self.cancel().as_numer_denom()[1], x,
                domain=domain)
            for logterm in self.atoms(log):
                singularities = singularities | solveset(logterm.args[0], x,
                    domain=domain)
            try:
                for s in singularities:
                    if value is S.NaN:
                        # no need to keep adding, it will stay NaN
                        break
                    if not s.is_comparable:
                        continue
                    if (a < s) == (s < b) == True:
                        value += -limit(self, x, s, "+") + limit(self, x, s, "-")
                    elif (b < s) == (s < a) == True:
                        value += limit(self, x, s, "+") - limit(self, x, s, "-")
            except TypeError:
                pass

        return value

    def _eval_power(self, expt) -> Expr | None:
        # subclass to compute self**other for cases when
        # other is not NaN, 0, or 1
        return None