Skip to content

Commit a8981cc

Browse files
authored
Merge pull request #49 from jverzani/bool3
bool3
2 parents e200066 + 22ed82c commit a8981cc

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "SymPyPythonCall"
22
uuid = "bc8888f7-b21e-4b7c-a06a-5d9c9496438c"
33
authors = ["jverzani <jverzani@gmail.com> and contributors"]
4-
version = "0.2.6"
4+
version = "0.3.0"
55

66

77
[deps]
@@ -28,7 +28,7 @@ PythonCall = "0.9"
2828
SpecialFunctions = "0.8, 0.9, 0.10, 1.0, 2"
2929
Symbolics = "5"
3030
SymbolicUtils = "1"
31-
SymPyCore = "0.1.6, 1"
31+
SymPyCore = "0.2, 1"
3232
julia = "1.6.1"
3333

3434

src/python_connection.jl

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,30 @@
11
## PythonCall specific usage
22
Base.convert(::Type{S}, x::Sym{T}) where {T <: PythonCall.Py, S<:Sym} = x
3+
Base.convert(::Type{S}, x::Sym{T}) where {T <: PythonCall.Py,
4+
S<:Sym{PythonCall.Py}} = x
35
Base.convert(::Type{S}, x::T) where {T<:PythonCall.Py, S <: SymbolicObject} = Sym(x)
46

57
SymPyCore._convert(::Type{T}, x) where {T} = pyconvert(T, x)
68
function SymPyCore._convert(::Type{Bool}, x::Py)
7-
pyconvert(Bool, x == _sympy_.logic.boolalg.BooleanTrue) && return true
8-
pyconvert(Bool, x == _sympy_.logic.boolalg.BooleanFalse) && return false
9+
pyisinstance(x, _sympy_.logic.boolalg.BooleanTrue) && return true
10+
pyisinstance(x, _sympy_.logic.boolalg.BooleanFalse) && return false
911
pyconvert(Bool, pybool(x))
1012
end
1113

14+
function SymPyCore.Bool3(x::Sym{T}) where {T <: PythonCall.Py}
15+
y = (x)
16+
isnothing(y) && return nothing
17+
if hasproperty(y, "is_Boolean")
18+
if pyconvert(Bool, y.is_Boolean)
19+
return SymPyCore._convert(Bool, y)
20+
end
21+
elseif hasproperty(y, "__bool__")
22+
if pyconvert(Bool, y.__bool__ != (Sym(nothing)))
23+
return pyconvert(Bool, y.__bool__())
24+
end
25+
end
26+
return nothing
27+
end
1228

1329
## Modifications for ↓, ↑
1430
Sym(x::Nothing) = Sym(pybuiltins.None)

0 commit comments

Comments
 (0)