From 00f36f9246e225a2bce12bfb426fd12dc4fc70c3 Mon Sep 17 00:00:00 2001 From: hhaensel <31985040+hhaensel@users.noreply.github.com> Date: Mon, 20 Jan 2025 15:22:25 +0100 Subject: [PATCH] PyList: fix pushfirst! for Julia 1.11, by adding prepend! (#588) --- src/Wrap/PyList.jl | 7 +++++++ test/Wrap.jl | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/src/Wrap/PyList.jl b/src/Wrap/PyList.jl index 69307c3a..d1422d12 100644 --- a/src/Wrap/PyList.jl +++ b/src/Wrap/PyList.jl @@ -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...) diff --git a/test/Wrap.jl b/test/Wrap.jl index fe8659e3..a1e2a359 100644 --- a/test/Wrap.jl +++ b/test/Wrap.jl @@ -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