From a572c5a6703e868c6e61c1d1e43d87ba8f259c86 Mon Sep 17 00:00:00 2001 From: Christopher Rowley Date: Sun, 31 May 2026 20:59:18 +0100 Subject: [PATCH 1/2] restore methods for !=, >= and > --- src/Core/Py.jl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Core/Py.jl b/src/Core/Py.jl index 262fb479..1b4f48fe 100644 --- a/src/Core/Py.jl +++ b/src/Core/Py.jl @@ -358,8 +358,11 @@ Base.broadcastable(x::Py) = Ref(x) # comparisons 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) = pyge(Bool, x, y) Base.:(<)(x::Py, y::Py) = pylt(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) @@ -376,11 +379,9 @@ Base.:(~)(x::Py) = pyinv(x) Base.:(+)(x::Py, y::Py) = pyadd(x, y) Base.:(-)(x::Py, y::Py) = pysub(x, y) Base.:(*)(x::Py, y::Py) = pymul(x, y) -# Base.:(+)(x::Py, y::Py) = pymatmul(x, y) Base.div(x::Py, y::Py) = pyfloordiv(x, y) Base.:(/)(x::Py, y::Py) = pytruediv(x, y) Base.rem(x::Py, y::Py) = pymod(x, y) -# Base.:(+)(x::Py, y::Py) = pydivmod(x, y) Base.:(<<)(x::Py, y::Py) = pylshift(x, y) Base.:(>>)(x::Py, y::Py) = pyrshift(x, y) Base.:(&)(x::Py, y::Py) = pyand(x, y) From a146dc95f4984683dfc22acf4248245427125d68 Mon Sep 17 00:00:00 2001 From: Christopher Rowley Date: Sun, 31 May 2026 21:10:51 +0100 Subject: [PATCH 2/2] update changelog and docs --- CHANGELOG.md | 4 +++- docs/src/v1-migration-guide.md | 12 ++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 44834668..fc221b66 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,9 @@ ## Unreleased (v1) * The vast majority of these changes are breaking, see the [v1 Migration Guide](@ref) for how to upgrade. * Changes to core functionality: - * Comparisons like `==(::Py, ::Py)`, `<(::Py, ::Number)`, `isless(::Number, ::Py)` now return `Bool` instead of `Py`. + * Comparisons like `==`, `<` and `isless` between `Py`s now return `Bool` instead of `Py`. + * Removed comparisons between `Py` and `Number` (like `Py(3) < 5`). + * Removed arithmetic between `Py` and `Number` (like `Py(2) * 10`). * Changes to `PythonCall.GC` (now more like `Base.GC`): * `enable(true)` replaces `enable()`. * `enable(false)` replaces `disable()`. diff --git a/docs/src/v1-migration-guide.md b/docs/src/v1-migration-guide.md index 87950289..e62926b6 100644 --- a/docs/src/v1-migration-guide.md +++ b/docs/src/v1-migration-guide.md @@ -4,18 +4,26 @@ Use this guide to help with migrating code from v0.9 to v1. ## Core functionality -Comparisons (`==`, `<`, etc.) between Python objects `Py`, or between `Py` and `Number`, +Comparisons (`==`, `<`, etc.) between Python objects `Py`, used to return `Py` but now return `Bool`. The old behaviour was a pun but broke the Base API behaviour of these functions. These comparisons will now raise an error if the underlying Python operation does not return `bool`. * Instead of `pytruth(Py(3) < Py(5))` use `Py(3) < Py(5)`. * Instead of `Py(3) < Py(5)` use `Py(Py(3) < Py(5))`. -* Instead of `np.array([1,2,3]) < Py(3)` use `pylt(np.array([1,2,3]), Py(3))`. This is +* Instead of `np.array([1,2,3]) < Py(3)` use `pylt(np.array([1,2,3]), 3)`. This is because comparisons on numpy arrays return arrays of `bool` rather than a single `bool`. * Instead of `pylt(Bool, Py(3), Py(5))` you can use `Py(3) < Py(5)`. +Comparisons and arithmetic (`==`, `<`, `+`, `*`, etc.) between `Py` and `Number` have +been removed. The old behaviour broke the PythonCall convention that the boundary +between Python and Julia is explicit. + +* Instead of `Py(3) < 10` use `Py(3) < Py(10)` or `pylt(Py(3), 10)`. +* Instead of `Py(5) * 6` use `Py(5) * Py(6)` or `pymul(Py(5), 6)`. +* Instead of `np.array([1,2,3]) < 3` use `pylt(np.array([1,2,3]), 3)`. + ## `PythonCall.GC` This submodule has been changed to closer mimic the `Base.GC` API.