Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "SymPyPythonCall"
uuid = "bc8888f7-b21e-4b7c-a06a-5d9c9496438c"
authors = ["jverzani <jverzani@gmail.com> and contributors"]
version = "0.2.1"
version = "0.2.2"

[deps]
CommonEq = "3709ef60-1bee-4518-9f2f-acd86f176c50"
Expand All @@ -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"


Expand Down
57 changes: 29 additions & 28 deletions src/python_connection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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 ↓, ↑
Expand Down Expand Up @@ -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


Expand Down