From 8df47049289a63f262a40714cf3aeb6770f0b74f 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 ++-- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/NEWS.md b/NEWS.md index 45d29ce2726cf..90b7d695cff24 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 6b109f29c0d62..becbe491695d9 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 471d4b6b0e19a..8eb1d71492334 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 e1388b29c8ff9..abb211821b2b4 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::