Skip to content

Commit 8f3b5ab

Browse files
authored
restore methods for !=, >= and > (#784)
* restore methods for !=, >= and > * update changelog and docs --------- Co-authored-by: Christopher Rowley <github.com/cjdoris>
1 parent 0225c36 commit 8f3b5ab

3 files changed

Lines changed: 16 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
## Unreleased (v1)
44
* The vast majority of these changes are breaking, see the [v1 Migration Guide](@ref) for how to upgrade.
55
* Changes to core functionality:
6-
* Comparisons like `==(::Py, ::Py)`, `<(::Py, ::Number)`, `isless(::Number, ::Py)` now return `Bool` instead of `Py`.
6+
* Comparisons like `==`, `<` and `isless` between `Py`s now return `Bool` instead of `Py`.
7+
* Removed comparisons between `Py` and `Number` (like `Py(3) < 5`).
8+
* Removed arithmetic between `Py` and `Number` (like `Py(2) * 10`).
79
* Changes to `PythonCall.GC` (now more like `Base.GC`):
810
* `enable(true)` replaces `enable()`.
911
* `enable(false)` replaces `disable()`.

docs/src/v1-migration-guide.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,26 @@ Use this guide to help with migrating code from v0.9 to v1.
44

55
## Core functionality
66

7-
Comparisons (`==`, `<`, etc.) between Python objects `Py`, or between `Py` and `Number`,
7+
Comparisons (`==`, `<`, etc.) between Python objects `Py`,
88
used to return `Py` but now return `Bool`. The old behaviour was a pun but broke the
99
Base API behaviour of these functions. These comparisons will now raise an error if the
1010
underlying Python operation does not return `bool`.
1111

1212
* Instead of `pytruth(Py(3) < Py(5))` use `Py(3) < Py(5)`.
1313
* Instead of `Py(3) < Py(5)` use `Py(Py(3) < Py(5))`.
14-
* Instead of `np.array([1,2,3]) < Py(3)` use `pylt(np.array([1,2,3]), Py(3))`. This is
14+
* Instead of `np.array([1,2,3]) < Py(3)` use `pylt(np.array([1,2,3]), 3)`. This is
1515
because comparisons on numpy arrays return arrays of `bool` rather than a single
1616
`bool`.
1717
* Instead of `pylt(Bool, Py(3), Py(5))` you can use `Py(3) < Py(5)`.
1818

19+
Comparisons and arithmetic (`==`, `<`, `+`, `*`, etc.) between `Py` and `Number` have
20+
been removed. The old behaviour broke the PythonCall convention that the boundary
21+
between Python and Julia is explicit.
22+
23+
* Instead of `Py(3) < 10` use `Py(3) < Py(10)` or `pylt(Py(3), 10)`.
24+
* Instead of `Py(5) * 6` use `Py(5) * Py(6)` or `pymul(Py(5), 6)`.
25+
* Instead of `np.array([1,2,3]) < 3` use `pylt(np.array([1,2,3]), 3)`.
26+
1927
## `PythonCall.GC`
2028

2129
This submodule has been changed to closer mimic the `Base.GC` API.

src/Core/Py.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,11 @@ Base.broadcastable(x::Py) = Ref(x)
358358

359359
# comparisons
360360
Base.:(==)(x::Py, y::Py) = pyeq(Bool, x, y)
361+
Base.:(!=)(x::Py, y::Py) = pyne(Bool, x, y)
361362
Base.:(<=)(x::Py, y::Py) = pyle(Bool, x, y)
363+
Base.:(>=)(x::Py, y::Py) = pyge(Bool, x, y)
362364
Base.:(<)(x::Py, y::Py) = pylt(Bool, x, y)
365+
Base.:(>)(x::Py, y::Py) = pygt(Bool, x, y)
363366
Base.isless(x::Py, y::Py) = pylt(Bool, x, y)
364367
Base.isequal(x::Py, y::Py) = pyeq(Bool, x, y)
365368

@@ -376,11 +379,9 @@ Base.:(~)(x::Py) = pyinv(x)
376379
Base.:(+)(x::Py, y::Py) = pyadd(x, y)
377380
Base.:(-)(x::Py, y::Py) = pysub(x, y)
378381
Base.:(*)(x::Py, y::Py) = pymul(x, y)
379-
# Base.:(+)(x::Py, y::Py) = pymatmul(x, y)
380382
Base.div(x::Py, y::Py) = pyfloordiv(x, y)
381383
Base.:(/)(x::Py, y::Py) = pytruediv(x, y)
382384
Base.rem(x::Py, y::Py) = pymod(x, y)
383-
# Base.:(+)(x::Py, y::Py) = pydivmod(x, y)
384385
Base.:(<<)(x::Py, y::Py) = pylshift(x, y)
385386
Base.:(>>)(x::Py, y::Py) = pyrshift(x, y)
386387
Base.:(&)(x::Py, y::Py) = pyand(x, y)

0 commit comments

Comments
 (0)