Skip to content

Commit bb45773

Browse files
authored
Bool3 (#546)
* move SymPyPyCall -> SymPy; breaking change * Bool3, bump
1 parent a6e74db commit bb45773

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "SymPy"
22
uuid = "24249f21-da20-56a4-8eb1-6a02cf4ae2e6"
3-
version = "2.0.1"
3+
version = "2.1.0"
44

55
[deps]
66
CommonEq = "3709ef60-1bee-4518-9f2f-acd86f176c50"
@@ -17,7 +17,7 @@ LinearAlgebra = "<0.0.1, 1.6"
1717
PyCall = "1.96.2"
1818
SpecialFunctions = "0.7, 0.8, 0.8, 0.10, 1, 2"
1919
SymbolicUtils = "1"
20-
SymPyCore = "0.1.6, 1"
20+
SymPyCore = "0.2, 1"
2121
julia = "1.6"
2222

2323
[extras]

src/SymPy.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,6 @@ include(joinpath(core_src_path, "gen_methods_sympy.jl"))
168168
include(joinpath(core_src_path, "additional_methods_sympy.jl"))
169169
include(joinpath(core_src_path, "show_sympy.jl"))
170170

171-
172171
include("python_connection.jl")
173172

174173
end # module

src/python_connection.jl

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99
# PyObject are needed for that.
1010

1111
Base.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
1213
Base.convert(::Type{S}, x::T) where {T<:PyObject, S <: SymbolicObject} = Sym(x)
1314

1415
SymPyCore._convert(::Type{T}, x) where {T} = convert(T, x)
16+
1517
function 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")
2325
end
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

3342
SymPyCore.:(x::PyObject) = x
3443
SymPyCore.:(d::Dict) = Dict((k) => (v) for (k,v) pairs(d))

0 commit comments

Comments
 (0)