Skip to content

Commit

Permalink
PyList: fix pushfirst! for Julia 1.11, by adding prepend! (#588)
Browse files Browse the repository at this point in the history
  • Loading branch information
hhaensel authored Jan 20, 2025
1 parent a61c022 commit 00f36f9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Wrap/PyList.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,13 @@ function Base.append!(x::PyList, vs)
return x
end

function Base.prepend!(x::PyList, vs)
for v in reverse(vs)
pushfirst!(x, v)
end
return x
end

function Base.push!(x::PyList, v1, v2, vs...)
push!(x, v1)
push!(x, v2, vs...)
Expand Down
7 changes: 7 additions & 0 deletions test/Wrap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,13 @@ end
@test_throws Exception append!(t, [nothing, missing])
@test t == [1, 2, 3, 4, 5, 6]
end
@testset "prepend!" begin
t = copy(z)
@test prepend!(t, [-3, -2, -1]) === t
@test t == [-3, -2, -1, 1, 2, 3]
@test_throws Exception append!(t, [nothing, missing])
@test t == [-3, -2, -1, 1, 2, 3]
end
@testset "pop!" begin
t = copy(z)
@test pop!(t) == 3
Expand Down

0 comments on commit 00f36f9

Please sign in to comment.