Skip to content

Commit

Permalink
Merge pull request #40 from jverzani/bool
Browse files Browse the repository at this point in the history
code cleanup
  • Loading branch information
jverzani authored Oct 25, 2023
2 parents b58aeb2 + a1db21f commit a624ea7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 30 deletions.
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 <[email protected]> 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

2 comments on commit a624ea7

@jverzani
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/94114

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.2.2 -m "<description of version>" a624ea73c33ee7bc1306e2cd5480f633549d93a4
git push origin v0.2.2

Please sign in to comment.