Skip to content

Commit 47dc548

Browse files
author
Christopher Doris
committed
comparisons now return Bool not Py
1 parent 333b9a3 commit 47dc548

File tree

3 files changed

+104
-19
lines changed

3 files changed

+104
-19
lines changed

docs/src/releasenotes.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
# Release Notes
22

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

1722
## 0.9.28 (2025-09-17)

src/Core/Py.jl

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -334,31 +334,31 @@ Base.broadcastable(x::Py) = Ref(x)
334334
(f::Py)(args...; kwargs...) = pycall(f, args...; kwargs...)
335335

336336
# comparisons
337-
Base.:(==)(x::Py, y::Py) = pyeq(x, y)
338-
Base.:(!=)(x::Py, y::Py) = pyne(x, y)
339-
Base.:(<=)(x::Py, y::Py) = pyle(x, y)
340-
Base.:(<)(x::Py, y::Py) = pylt(x, y)
341-
Base.:(>=)(x::Py, y::Py) = pyge(x, y)
342-
Base.:(>)(x::Py, y::Py) = pygt(x, y)
337+
Base.:(==)(x::Py, y::Py) = pyeq(Bool, x, y)
338+
Base.:(!=)(x::Py, y::Py) = pyne(Bool, x, y)
339+
Base.:(<=)(x::Py, y::Py) = pyle(Bool, x, y)
340+
Base.:(<)(x::Py, y::Py) = pylt(Bool, x, y)
341+
Base.:(>=)(x::Py, y::Py) = pyge(Bool, x, y)
342+
Base.:(>)(x::Py, y::Py) = pygt(Bool, x, y)
343343
Base.isless(x::Py, y::Py) = pylt(Bool, x, y)
344344
Base.isequal(x::Py, y::Py) = pyeq(Bool, x, y)
345345

346346
# we also allow comparison with numbers
347-
Base.:(==)(x::Py, y::Number) = pyeq(x, y)
348-
Base.:(!=)(x::Py, y::Number) = pyne(x, y)
349-
Base.:(<=)(x::Py, y::Number) = pyle(x, y)
350-
Base.:(<)(x::Py, y::Number) = pylt(x, y)
351-
Base.:(>=)(x::Py, y::Number) = pyge(x, y)
352-
Base.:(>)(x::Py, y::Number) = pygt(x, y)
347+
Base.:(==)(x::Py, y::Number) = pyeq(Bool, x, y)
348+
Base.:(!=)(x::Py, y::Number) = pyne(Bool, x, y)
349+
Base.:(<=)(x::Py, y::Number) = pyle(Bool, x, y)
350+
Base.:(<)(x::Py, y::Number) = pylt(Bool, x, y)
351+
Base.:(>=)(x::Py, y::Number) = pyge(Bool, x, y)
352+
Base.:(>)(x::Py, y::Number) = pygt(Bool, x, y)
353353
Base.isless(x::Py, y::Number) = pylt(Bool, x, y)
354354
Base.isequal(x::Py, y::Number) = pyeq(Bool, x, y)
355355

356-
Base.:(==)(x::Number, y::Py) = pyeq(x, y)
357-
Base.:(!=)(x::Number, y::Py) = pyne(x, y)
358-
Base.:(<=)(x::Number, y::Py) = pyle(x, y)
359-
Base.:(<)(x::Number, y::Py) = pylt(x, y)
360-
Base.:(>=)(x::Number, y::Py) = pyge(x, y)
361-
Base.:(>)(x::Number, y::Py) = pygt(x, y)
356+
Base.:(==)(x::Number, y::Py) = pyeq(Bool, x, y)
357+
Base.:(!=)(x::Number, y::Py) = pyne(Bool, x, y)
358+
Base.:(<=)(x::Number, y::Py) = pyle(Bool, x, y)
359+
Base.:(<)(x::Number, y::Py) = pylt(Bool, x, y)
360+
Base.:(>=)(x::Number, y::Py) = pyge(Bool, x, y)
361+
Base.:(>)(x::Number, y::Py) = pygt(Bool, x, y)
362362
Base.isless(x::Number, y::Py) = pylt(Bool, x, y)
363363
Base.isequal(x::Number, y::Py) = pyeq(Bool, x, y)
364364

test/Core.jl

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,86 @@
220220
@test Base.Docs.getdoc(pybuiltins.int) isa Markdown.MD
221221
@test Base.Docs.getdoc(PythonCall.PyNULL) === nothing
222222
end
223+
@testset "comparisons" begin
224+
@testset "Py vs Py" begin
225+
# ==
226+
@test Py(1) == Py(1)
227+
@test !(Py(1) == Py(2))
228+
@test !(Py(1) == Py(0))
229+
# !=
230+
@test Py(2) != Py(1)
231+
@test Py(2) != Py(3)
232+
@test !(Py(2) != Py(2))
233+
# <
234+
@test Py(3) < Py(4)
235+
@test !(Py(3) < Py(3))
236+
@test !(Py(3) < Py(2))
237+
# <=
238+
@test Py(4) <= Py(5)
239+
@test Py(4) <= Py(4)
240+
@test !(Py(4) <= Py(3))
241+
# >
242+
@test Py(5) > Py(4)
243+
@test !(Py(5) > Py(5))
244+
@test !(Py(5) > Py(6))
245+
# >=
246+
@test Py(5) >= Py(4)
247+
@test Py(5) >= Py(5)
248+
@test !(Py(5) >= Py(6))
249+
end
250+
@testset "Py vs Number" begin
251+
# ==
252+
@test Py(1) == 1
253+
@test !(Py(1) == 2)
254+
@test !(Py(1) == 0)
255+
# !=
256+
@test Py(2) != 1
257+
@test Py(2) != 3
258+
@test !(Py(2) != 2)
259+
# <
260+
@test Py(3) < 4
261+
@test !(Py(3) < 3)
262+
@test !(Py(3) < 2)
263+
# <=
264+
@test Py(4) <= 5
265+
@test Py(4) <= 4
266+
@test !(Py(4) <= 3)
267+
# >
268+
@test Py(5) > 4
269+
@test !(Py(5) > 5)
270+
@test !(Py(5) > 6)
271+
# >=
272+
@test Py(5) >= 4
273+
@test Py(5) >= 5
274+
@test !(Py(5) >= 6)
275+
end
276+
@testset "Number vs Py" begin
277+
# ==
278+
@test 1 == Py(1)
279+
@test !(1 == Py(2))
280+
@test !(1 == Py(0))
281+
# !=
282+
@test 2 != Py(1)
283+
@test 2 != Py(3)
284+
@test !(2 != Py(2))
285+
# <
286+
@test 3 < Py(4)
287+
@test !(3 < Py(3))
288+
@test !(3 < Py(2))
289+
# <=
290+
@test 4 <= Py(5)
291+
@test 4 <= Py(4)
292+
@test !(4 <= Py(3))
293+
# >
294+
@test 5 > Py(4)
295+
@test !(5 > Py(5))
296+
@test !(5 > Py(6))
297+
# >=
298+
@test 5 >= Py(4)
299+
@test 5 >= Py(5)
300+
@test !(5 >= Py(6))
301+
end
302+
end
223303
end
224304

225305
@testitem "iter" begin

0 commit comments

Comments
 (0)