Skip to content

Commit 9631cb7

Browse files
committed
Remove Py-Number arithmetic methods
1 parent d8fe069 commit 9631cb7

File tree

3 files changed

+5
-107
lines changed

3 files changed

+5
-107
lines changed

src/Core/Py.jl

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -369,19 +369,6 @@ Base.:(<)(x::Py, y::Py) = pylt(Bool, x, y)
369369
Base.isless(x::Py, y::Py) = pylt(Bool, x, y)
370370
Base.isequal(x::Py, y::Py) = pyeq(Bool, x, y)
371371

372-
# we also allow comparison with numbers
373-
Base.:(==)(x::Py, y::Number) = pyeq(Bool, x, y)
374-
Base.:(<=)(x::Py, y::Number) = pyle(Bool, x, y)
375-
Base.:(<)(x::Py, y::Number) = pylt(Bool, x, y)
376-
Base.isless(x::Py, y::Number) = pylt(Bool, x, y)
377-
Base.isequal(x::Py, y::Number) = pyeq(Bool, x, y)
378-
379-
Base.:(==)(x::Number, y::Py) = pyeq(Bool, x, y)
380-
Base.:(<=)(x::Number, y::Py) = pyle(Bool, x, y)
381-
Base.:(<)(x::Number, y::Py) = pylt(Bool, x, y)
382-
Base.isless(x::Number, y::Py) = pylt(Bool, x, y)
383-
Base.isequal(x::Number, y::Py) = pyeq(Bool, x, y)
384-
385372
Base.zero(::Type{Py}) = pyint(0)
386373
Base.one(::Type{Py}) = pyint(1)
387374

@@ -407,44 +394,7 @@ Base.xor(x::Py, y::Py) = pyxor(x, y)
407394
Base.:(|)(x::Py, y::Py) = pyor(x, y)
408395
Base.:(^)(x::Py, y::Py) = pypow(x, y)
409396

410-
# also allow binary arithmetic with numbers
411-
Base.:(+)(x::Number, y::Py) = pyadd(x, y)
412-
Base.:(-)(x::Number, y::Py) = pysub(x, y)
413-
Base.:(*)(x::Number, y::Py) = pymul(x, y)
414-
# Base.:(+)(x::Number, y::Py) = pymatmul(x, y)
415-
Base.div(x::Number, y::Py) = pyfloordiv(x, y)
416-
Base.:(/)(x::Number, y::Py) = pytruediv(x, y)
417-
Base.rem(x::Number, y::Py) = pymod(x, y)
418-
# Base.:(+)(x::Number, y::Py) = pydivmod(x, y)
419-
Base.:(<<)(x::Number, y::Py) = pylshift(x, y)
420-
Base.:(>>)(x::Number, y::Py) = pyrshift(x, y)
421-
Base.:(&)(x::Number, y::Py) = pyand(x, y)
422-
Base.xor(x::Number, y::Py) = pyxor(x, y)
423-
Base.:(|)(x::Number, y::Py) = pyor(x, y)
424-
Base.:(^)(x::Number, y::Py) = pypow(x, y)
425-
426-
Base.:(+)(x::Py, y::Number) = pyadd(x, y)
427-
Base.:(-)(x::Py, y::Number) = pysub(x, y)
428-
Base.:(*)(x::Py, y::Number) = pymul(x, y)
429-
# Base.:(+)(x::Py, y::Number) = pymatmul(x, y)
430-
Base.div(x::Py, y::Number) = pyfloordiv(x, y)
431-
Base.:(/)(x::Py, y::Number) = pytruediv(x, y)
432-
Base.rem(x::Py, y::Number) = pymod(x, y)
433-
# Base.:(+)(x::Py, y::Number) = pydivmod(x, y)
434-
Base.:(<<)(x::Py, y::Number) = pylshift(x, y)
435-
Base.:(>>)(x::Py, y::Number) = pyrshift(x, y)
436-
Base.:(&)(x::Py, y::Number) = pyand(x, y)
437-
Base.xor(x::Py, y::Number) = pyxor(x, y)
438-
Base.:(|)(x::Py, y::Number) = pyor(x, y)
439-
Base.:(^)(x::Py, y::Number) = pypow(x, y)
440-
441397
Base.powermod(x::Py, y::Py, z::Py) = pypow(x, y, z)
442-
Base.powermod(x::Number, y::Py, z::Py) = pypow(x, y, z)
443-
Base.powermod(x::Py, y::Number, z::Py) = pypow(x, y, z)
444-
Base.powermod(x::Py, y::Py, z::Number) = pypow(x, y, z)
445-
Base.powermod(x::Number, y::Number, z::Py) = pypow(x, y, z)
446-
Base.powermod(x::Number, y::Py, z::Number) = pypow(x, y, z)
447-
Base.powermod(x::Py, y::Number, z::Number) = pypow(x, y, z)
448398

449399
# documentation
450400
function Base.Docs.getdoc(x::Py, @nospecialize(sig) = Union{})

test/Core.jl

Lines changed: 4 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -247,58 +247,6 @@
247247
@test Py(5) >= Py(5)
248248
@test !(Py(5) >= Py(6))
249249
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
302250
end
303251
end
304252

@@ -865,13 +813,13 @@ end
865813
@testitem "Base.jl" begin
866814
@testset "broadcast" begin
867815
# Py always broadcasts as a scalar
868-
x = [1 2; 3 4] .+ Py(1)
869-
@test isequal(x, [Py(2) Py(3); Py(4) Py(5)])
870-
x = Py("foo") .* [1 2; 3 4]
816+
x = Py.([1 2; 3 4]) .+ Py(1)
817+
@test isequal(x, Py.([2 3; 4 5]))
818+
x = Py("foo") .* Py.([1 2; 3 4])
871819
@test isequal(x, [Py("foo") Py("foofoo"); Py("foofoofoo") Py("foofoofoofoo")])
872820
# this previously treated the list as a shape (2,) object
873821
# but now tries to do `1 + [1, 2]` which properly fails
874-
@test_throws PyException [1 2; 3 4] .+ pylist([1, 2])
822+
@test_throws PyException Py.([1 2; 3 4]) .+ pylist([1, 2])
875823
end
876824
@testset "showable" begin
877825
@test showable(MIME("text/plain"), Py(nothing))

test/JlWrap.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ end
718718
y = pytextio(x)
719719
z = y.fileno()
720720
@test pyisinstance(z, pybuiltins.int)
721-
@test z == Base.cconvert(Cint, fd(x))
721+
@test pyconvert(Int, z) == Base.cconvert(Cint, fd(x))
722722
end
723723
end
724724
@testset "flush" begin

0 commit comments

Comments
 (0)