From beb83f271e7f201536fe34b26041711e47d6213f Mon Sep 17 00:00:00 2001 From: jake bolewski Date: Wed, 4 Mar 2015 11:39:07 -0500 Subject: [PATCH] force push! and unshift! to need at least one item --- NEWS.md | 2 ++ base/abstractarray.jl | 2 -- base/deprecated.jl | 5 +++++ doc/stdlib/collections.rst | 4 ++-- test/arrayops.jl | 6 ++++++ 5 files changed, 15 insertions(+), 4 deletions(-) diff --git a/NEWS.md b/NEWS.md index 45d29ce2726cf1..90b7d695cff24e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -197,6 +197,8 @@ Library improvements Deprecated or removed --------------------- + * `push!(A)` has been deprecated, use `append!` instead of splatting arguments to `push!` ([#10400]). + * `names` for composite datatypes has been deprecated and renamed to `fieldnames` ([#10332]). diff --git a/base/abstractarray.jl b/base/abstractarray.jl index 6b109f29c0d62b..becbe491695d9a 100644 --- a/base/abstractarray.jl +++ b/base/abstractarray.jl @@ -1453,10 +1453,8 @@ end # multi-item push!, unshift! (built on top of type-specific 1-item version) # (note: must not cause a dispatch loop when 1-item case is not defined) -push!(A) = A push!(A, a, b) = push!(push!(A, a), b) push!(A, a, b, c...) = push!(push!(A, a, b), c...) -unshift!(A) = A unshift!(A, a, b) = unshift!(unshift!(A, b), a) unshift!(A, a, b, c...) = unshift!(unshift!(A, c...), a, b) diff --git a/base/deprecated.jl b/base/deprecated.jl index 471d4b6b0e19a4..8eb1d71492334d 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -307,3 +307,8 @@ end @deprecate names(t::DataType) fieldnames(t) @deprecate names(v) fieldnames(v) + +function push!(A) + depwarn("push!(A) has been deprecated", :push!) + A +end diff --git a/doc/stdlib/collections.rst b/doc/stdlib/collections.rst index e1388b29c8ff91..abb211821b2b4c 100644 --- a/doc/stdlib/collections.rst +++ b/doc/stdlib/collections.rst @@ -800,7 +800,7 @@ Dequeues .. function:: push!(collection, items...) -> collection - Insert zero or more ``items`` at the end of ``collection``. + Insert one or more ``items`` at the end of ``collection``. .. doctest:: @@ -846,7 +846,7 @@ Dequeues .. function:: unshift!(collection, items...) -> collection - Insert zero or more ``items`` at the beginning of ``collection``. + Insert one or more ``items`` at the beginning of ``collection``. .. doctest:: diff --git a/test/arrayops.jl b/test/arrayops.jl index 60b8b8da0ff5bf..fffd6f44eea976 100644 --- a/test/arrayops.jl +++ b/test/arrayops.jl @@ -832,6 +832,12 @@ A = [NaN]; B = [NaN] @test isequal(A,B) @test A!==B +# test that single arugment push!, unshift! are not defined +let A = [] + @test_throws MethodError push!(a) + @test_throws MethodError unshift!(a) +end + # complete testsuite for reducedim # Inferred types