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
50 changes: 0 additions & 50 deletions src/Core/Py.jl
Original file line number Diff line number Diff line change
Expand Up @@ -369,19 +369,6 @@ Base.:(<)(x::Py, y::Py) = pylt(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(Bool, x, y)
Base.:(<=)(x::Py, y::Number) = pyle(Bool, x, y)
Base.:(<)(x::Py, y::Number) = pylt(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(Bool, x, y)
Base.:(<=)(x::Number, y::Py) = pyle(Bool, x, y)
Base.:(<)(x::Number, y::Py) = pylt(Bool, x, y)
Base.isless(x::Number, y::Py) = pylt(Bool, x, y)
Base.isequal(x::Number, y::Py) = pyeq(Bool, x, y)

Base.zero(::Type{Py}) = pyint(0)
Base.one(::Type{Py}) = pyint(1)

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

# also allow binary arithmetic with numbers
Base.:(+)(x::Number, y::Py) = pyadd(x, y)
Base.:(-)(x::Number, y::Py) = pysub(x, y)
Base.:(*)(x::Number, y::Py) = pymul(x, y)
# Base.:(+)(x::Number, y::Py) = pymatmul(x, y)
Base.div(x::Number, y::Py) = pyfloordiv(x, y)
Base.:(/)(x::Number, y::Py) = pytruediv(x, y)
Base.rem(x::Number, y::Py) = pymod(x, y)
# Base.:(+)(x::Number, y::Py) = pydivmod(x, y)
Base.:(<<)(x::Number, y::Py) = pylshift(x, y)
Base.:(>>)(x::Number, y::Py) = pyrshift(x, y)
Base.:(&)(x::Number, y::Py) = pyand(x, y)
Base.xor(x::Number, y::Py) = pyxor(x, y)
Base.:(|)(x::Number, y::Py) = pyor(x, y)
Base.:(^)(x::Number, y::Py) = pypow(x, y)

Base.:(+)(x::Py, y::Number) = pyadd(x, y)
Base.:(-)(x::Py, y::Number) = pysub(x, y)
Base.:(*)(x::Py, y::Number) = pymul(x, y)
# Base.:(+)(x::Py, y::Number) = pymatmul(x, y)
Base.div(x::Py, y::Number) = pyfloordiv(x, y)
Base.:(/)(x::Py, y::Number) = pytruediv(x, y)
Base.rem(x::Py, y::Number) = pymod(x, y)
# Base.:(+)(x::Py, y::Number) = pydivmod(x, y)
Base.:(<<)(x::Py, y::Number) = pylshift(x, y)
Base.:(>>)(x::Py, y::Number) = pyrshift(x, y)
Base.:(&)(x::Py, y::Number) = pyand(x, y)
Base.xor(x::Py, y::Number) = pyxor(x, y)
Base.:(|)(x::Py, y::Number) = pyor(x, y)
Base.:(^)(x::Py, y::Number) = pypow(x, y)

Base.powermod(x::Py, y::Py, z::Py) = pypow(x, y, z)
Base.powermod(x::Number, y::Py, z::Py) = pypow(x, y, z)
Base.powermod(x::Py, y::Number, z::Py) = pypow(x, y, z)
Base.powermod(x::Py, y::Py, z::Number) = pypow(x, y, z)
Base.powermod(x::Number, y::Number, z::Py) = pypow(x, y, z)
Base.powermod(x::Number, y::Py, z::Number) = pypow(x, y, z)
Base.powermod(x::Py, y::Number, z::Number) = pypow(x, y, z)

# documentation
function Base.Docs.getdoc(x::Py, @nospecialize(sig) = Union{})
Expand Down
60 changes: 4 additions & 56 deletions test/Core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -247,58 +247,6 @@
@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

Expand Down Expand Up @@ -865,13 +813,13 @@ end
@testitem "Base.jl" begin
@testset "broadcast" begin
# Py always broadcasts as a scalar
x = [1 2; 3 4] .+ Py(1)
@test isequal(x, [Py(2) Py(3); Py(4) Py(5)])
x = Py("foo") .* [1 2; 3 4]
x = Py.([1 2; 3 4]) .+ Py(1)
@test isequal(x, Py.([2 3; 4 5]))
x = Py("foo") .* Py.([1 2; 3 4])
@test isequal(x, [Py("foo") Py("foofoo"); Py("foofoofoo") Py("foofoofoofoo")])
# this previously treated the list as a shape (2,) object
# but now tries to do `1 + [1, 2]` which properly fails
@test_throws PyException [1 2; 3 4] .+ pylist([1, 2])
@test_throws PyException Py.([1 2; 3 4]) .+ pylist([1, 2])
end
@testset "showable" begin
@test showable(MIME("text/plain"), Py(nothing))
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 z == Base.cconvert(Cint, fd(x))
@test pyconvert(Int, z) == Base.cconvert(Cint, fd(x))
end
end
@testset "flush" begin
Expand Down
Loading