diff --git a/Project.toml b/Project.toml index 8a53f2c..204693f 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "SymPyPythonCall" uuid = "bc8888f7-b21e-4b7c-a06a-5d9c9496438c" authors = ["jverzani and contributors"] -version = "0.2.1" +version = "0.2.2" [deps] CommonEq = "3709ef60-1bee-4518-9f2f-acd86f176c50" @@ -27,7 +27,7 @@ PythonCall = "0.9" SpecialFunctions = "0.8, 0.9, 0.10, 1.0, 2" Symbolics = "5" SymbolicUtils = "1" -SymPyCore = "0.1" +SymPyCore = "0.1.3, 1" julia = "1.6.1" diff --git a/src/python_connection.jl b/src/python_connection.jl index ec4cdf6..b6b475b 100644 --- a/src/python_connection.jl +++ b/src/python_connection.jl @@ -6,7 +6,11 @@ Base.convert(::Type{S}, x::Sym{T}) where {T <: PythonCall.Py, S<:Sym} = x Base.convert(::Type{S}, x::T) where {T<:PythonCall.Py, S <: SymbolicObject} = Sym(x) SymPyCore._convert(::Type{T}, x) where {T} = pyconvert(T, x) -SymPyCore._convert(::Type{Bool}, x) = pyconvert(Bool, pybool(x)) +function SymPyCore._convert(::Type{Bool}, x::Py) + pyconvert(Bool, x == _sympy_.logic.boolalg.BooleanTrue) && return true + pyconvert(Bool, x == _sympy_.logic.boolalg.BooleanFalse) && return false + pyconvert(Bool, pybool(x)) +end ## Modifications for ↓, ↑ @@ -53,42 +57,39 @@ function Base.getproperty(x::SymbolicObject{T}, a::Symbol) where {T <: PythonCal Base.depwarn("The field `.py` has been renamed `.o`", :getproperty) return getfield(x,:o) end + val = ↓(x) - if hasproperty(val, a) - meth = getproperty(val, a) + !hasproperty(val, a) && return nothing # not a property - pyconvert(Bool, meth == pybuiltins.None) && return nothing + meth = getproperty(val, a) - if hasproperty(meth, "is_Boolean") - o = Sym(getproperty(meth, "is_Boolean")) - o == Sym(true) && return true - a == :is_Boolean && return o == Sym(False) ? false : nothing + pyconvert(Bool, meth == pybuiltins.None) && return nothing + + if hasproperty(meth, "is_Boolean") + if pyconvert(Bool, meth.is_Boolean == true) + return meth == _sympy_.logic.boolalg.BooleanFalse end + end - # __class__ dispath - if hasproperty(meth, :__class__) - cnm = string(meth.__class__.__name__) - if cnm == "bool" - a = Sym(meth) - return a == Sym(true) ? true : - a == Sym(false) ? false : nothing - end - if cnm == "module" - # treat modules, callsm others differently - return Sym(meth) - end + # __class__ dispatch + if hasproperty(meth, :__class__) + cnm = string(meth.__class__.__name__) + if cnm == "bool" + return pyconvert(Bool, meth) end - ## __function__ - if hasproperty(meth, "__call__") - #meth = getproperty(meth, "__call__") - return SymPyCore.SymbolicCallable(meth) + if cnm == "module" + # treat modules, callsm others differently + return Sym(meth) end + end - return ↑(convert(PythonCall.Py, meth)) - + ## __call__ + if hasproperty(meth, "__call__") + return SymPyCore.SymbolicCallable(meth) end - # not a property; should this error - return nothing + + return ↑(convert(PythonCall.Py, meth)) + end