99# PyObject are needed for that.
1010
1111Base. convert(:: Type{S} , x:: Sym{T} ) where {T<: PyObject , S<: Sym } = x
12+ Base. convert(:: Type{S} , x:: Sym{T} ) where {T<: PyObject , S<: Sym{PyObject} } = x
1213Base. convert(:: Type{S} , x:: T ) where {T<: PyObject , S <: SymbolicObject } = Sym(x)
1314
1415SymPyCore. _convert(:: Type{T} , x) where {T} = convert(T, x)
16+
1517function SymPyCore. _convert(:: Type{Bool} , x:: PyObject )
1618 x == _sympy_. logic. boolalg. BooleanTrue && return true
1719 x == _sympy_. logic. boolalg. BooleanFalse && return false
@@ -22,13 +24,20 @@ function SymPyCore._convert(::Type{Bool}, x::PyObject)
2224 error(" Can't convert $x to boolean" )
2325end
2426
25-
26- # # Modifications for ↓, ↑
27- Sym(x:: Nothing ) = Sym(PyObject(nothing ))
28- Sym(x:: Bool ) = Sym(PyObject(x))
29- Sym(x:: Integer ) = Sym(_sympy_. Integer(x)) # slight improvement over sympify
30- Sym(x:: AbstractFloat ) = Sym(_sympy_. Float(x))
31-
27+ function SymPyCore. Bool3(x:: Sym{T} ) where {T <: PyObject }
28+ y = ↓ (x)
29+ isnothing(y) && return nothing
30+ if hasproperty(y, " is_Boolean" )
31+ if convert(Bool, y. is_Boolean)
32+ return SymPyCore. _convert(Bool, y)
33+ end
34+ elseif hasproperty(y, " __bool__" )
35+ if convert(Bool, y != ↓ (Sym(nothing )))
36+ return convert(Bool, y. __bool__())
37+ end
38+ end
39+ return nothing
40+ end
3241
3342SymPyCore.:↓ (x:: PyObject ) = x
3443SymPyCore.:↓ (d:: Dict ) = Dict(↓ (k) => ↓ (v) for (k,v) ∈ pairs(d))
0 commit comments