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
7 changes: 6 additions & 1 deletion docs/src/releasenotes.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# Release Notes

## Unreleased (v1)
* `PythonCall.GC` is now more like `Base.GC`: `enable(true)` replaces `enable()`, `enable(false)` replaces `disable()`, and `gc()` is added.
* Breaking changes to `PythonCall.GC`, which is now more like `Base.GC`:
* `enable(true)` replaces `enable()`.
* `enable(false)` replaces `disable()`.
* `gc()` added.
* Breaking changes to Julia wrapper types:
* Classes renamed: `ValueBase` to `JlBase`, `AnyValue` to `Jl`, `ArrayValue` to `JlArray`, etc.
* Classes removed: `RawValue`, `ModuleValue`, `TypeValue`, `NumberValue`, `ComplexValue`, `RealValue`, `RationalValue`, `IntegerValue`.
Expand All @@ -12,6 +15,8 @@
* Methods removed: `_jl_raw()`.
* `pyjl(x)` now always returns a `juliacall.Jl` (it used to select a wrapper type if possible).
* `pyjltype(x)` removed.
* Other breaking changes:
* Comparisons like `==(::Py, ::Py)`, `<(::Py, ::Number)`, `isless(::Number, ::Py)` now return `Bool` instead of `Py`.
* New functions: `pyjlarray`, `pyjldict`, `pyjlset`.

## Unreleased
Expand Down
36 changes: 18 additions & 18 deletions src/Core/Py.jl
Original file line number Diff line number Diff line change
Expand Up @@ -363,31 +363,31 @@ Base.broadcastable(x::Py) = Ref(x)
(f::Py)(args...; kwargs...) = pycall(f, args...; kwargs...)

# comparisons
Base.:(==)(x::Py, y::Py) = pyeq(x, y)
Base.:(!=)(x::Py, y::Py) = pyne(x, y)
Base.:(<=)(x::Py, y::Py) = pyle(x, y)
Base.:(<)(x::Py, y::Py) = pylt(x, y)
Base.:(>=)(x::Py, y::Py) = pyge(x, y)
Base.:(>)(x::Py, y::Py) = pygt(x, y)
Base.:(==)(x::Py, y::Py) = pyeq(Bool, x, y)
Base.:(!=)(x::Py, y::Py) = pyne(Bool, x, y)
Base.:(<=)(x::Py, y::Py) = pyle(Bool, x, y)
Base.:(<)(x::Py, y::Py) = pylt(Bool, x, y)
Base.:(>=)(x::Py, y::Py) = pyge(Bool, x, y)
Base.:(>)(x::Py, y::Py) = pygt(Bool, x, y)
Base.isless(x::Py, y::Py) = pylt(Bool, x, y)
Base.isequal(x::Py, y::Py) = pyeq(Bool, x, y)

# we also allow comparison with numbers
Base.:(==)(x::Py, y::Number) = pyeq(x, y)
Base.:(!=)(x::Py, y::Number) = pyne(x, y)
Base.:(<=)(x::Py, y::Number) = pyle(x, y)
Base.:(<)(x::Py, y::Number) = pylt(x, y)
Base.:(>=)(x::Py, y::Number) = pyge(x, y)
Base.:(>)(x::Py, y::Number) = pygt(x, y)
Base.:(==)(x::Py, y::Number) = pyeq(Bool, x, y)
Base.:(!=)(x::Py, y::Number) = pyne(Bool, x, y)
Base.:(<=)(x::Py, y::Number) = pyle(Bool, x, y)
Base.:(<)(x::Py, y::Number) = pylt(Bool, x, y)
Base.:(>=)(x::Py, y::Number) = pyge(Bool, x, y)
Base.:(>)(x::Py, y::Number) = pygt(Bool, x, y)
Base.isless(x::Py, y::Number) = pylt(Bool, x, y)
Base.isequal(x::Py, y::Number) = pyeq(Bool, x, y)

Base.:(==)(x::Number, y::Py) = pyeq(x, y)
Base.:(!=)(x::Number, y::Py) = pyne(x, y)
Base.:(<=)(x::Number, y::Py) = pyle(x, y)
Base.:(<)(x::Number, y::Py) = pylt(x, y)
Base.:(>=)(x::Number, y::Py) = pyge(x, y)
Base.:(>)(x::Number, y::Py) = pygt(x, y)
Base.:(==)(x::Number, y::Py) = pyeq(Bool, x, y)
Base.:(!=)(x::Number, y::Py) = pyne(Bool, x, y)
Base.:(<=)(x::Number, y::Py) = pyle(Bool, x, y)
Base.:(<)(x::Number, y::Py) = pylt(Bool, x, y)
Base.:(>=)(x::Number, y::Py) = pyge(Bool, x, y)
Base.:(>)(x::Number, y::Py) = pygt(Bool, x, y)
Base.isless(x::Number, y::Py) = pylt(Bool, x, y)
Base.isequal(x::Number, y::Py) = pyeq(Bool, x, y)

Expand Down
2 changes: 1 addition & 1 deletion src/JlWrap/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pyjlio_closed(io::IO) = Py(!isopen(io))
pyjl_handle_error_type(::typeof(pyjlio_closed), io, exc) =
exc isa MethodError && exc.f === isopen ? pybuiltins.ValueError : PyNULL

pyjlio_fileno(io::IO) = Py(fd(io))
pyjlio_fileno(io::IO) = Py(Base.cconvert(Cint, fd(io))::Cint)
pyjl_handle_error_type(::typeof(pyjlio_fileno), io, exc) =
exc isa MethodError && exc.f === fd ? pybuiltins.ValueError : PyNULL

Expand Down
80 changes: 80 additions & 0 deletions test/Core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,86 @@
@test Base.Docs.getdoc(pybuiltins.int) isa Markdown.MD
@test Base.Docs.getdoc(PythonCall.PyNULL) === nothing
end
@testset "comparisons" begin
@testset "Py vs Py" begin
# ==
@test Py(1) == Py(1)
@test !(Py(1) == Py(2))
@test !(Py(1) == Py(0))
# !=
@test Py(2) != Py(1)
@test Py(2) != Py(3)
@test !(Py(2) != Py(2))
# <
@test Py(3) < Py(4)
@test !(Py(3) < Py(3))
@test !(Py(3) < Py(2))
# <=
@test Py(4) <= Py(5)
@test Py(4) <= Py(4)
@test !(Py(4) <= Py(3))
# >
@test Py(5) > Py(4)
@test !(Py(5) > Py(5))
@test !(Py(5) > Py(6))
# >=
@test Py(5) >= Py(4)
@test Py(5) >= Py(5)
@test !(Py(5) >= Py(6))
end
@testset "Py vs Number" begin
# ==
@test Py(1) == 1
@test !(Py(1) == 2)
@test !(Py(1) == 0)
# !=
@test Py(2) != 1
@test Py(2) != 3
@test !(Py(2) != 2)
# <
@test Py(3) < 4
@test !(Py(3) < 3)
@test !(Py(3) < 2)
# <=
@test Py(4) <= 5
@test Py(4) <= 4
@test !(Py(4) <= 3)
# >
@test Py(5) > 4
@test !(Py(5) > 5)
@test !(Py(5) > 6)
# >=
@test Py(5) >= 4
@test Py(5) >= 5
@test !(Py(5) >= 6)
end
@testset "Number vs Py" begin
# ==
@test 1 == Py(1)
@test !(1 == Py(2))
@test !(1 == Py(0))
# !=
@test 2 != Py(1)
@test 2 != Py(3)
@test !(2 != Py(2))
# <
@test 3 < Py(4)
@test !(3 < Py(3))
@test !(3 < Py(2))
# <=
@test 4 <= Py(5)
@test 4 <= Py(4)
@test !(4 <= Py(3))
# >
@test 5 > Py(4)
@test !(5 > Py(5))
@test !(5 > Py(6))
# >=
@test 5 >= Py(4)
@test 5 >= Py(5)
@test !(5 >= Py(6))
end
end
end

@testitem "iter" begin
Expand Down
2 changes: 1 addition & 1 deletion test/JlWrap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ end
y = pytextio(x)
z = y.fileno()
@test pyisinstance(z, pybuiltins.int)
@test pyeq(Bool, z, fd(x))
@test z == Base.cconvert(Cint, fd(x))
end
end
@testset "flush" begin
Expand Down
Loading