Skip to content

Commit 743e966

Browse files
committed
deprecate copy! for sets and dicts (part of #24808)
1 parent 710a3d8 commit 743e966

File tree

5 files changed

+13
-11
lines changed

5 files changed

+13
-11
lines changed

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,9 @@ Deprecated or removed
686686
* `cumsum`, `cumprod`, `accumulate`, and their mutating versions now require a `dim`
687687
argument instead of defaulting to using the first dimension ([#24684]).
688688

689+
* `copy!` is deprecated for `AbstractSet` and `Associative`, with the intention to re-enable
690+
it with a cleaner meaning in a future version ([#24844]).
691+
689692
Command-line option changes
690693
---------------------------
691694

base/array.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,12 @@ function grow_to!(dest, itr, st)
630630
push!(dest, el::T)
631631
else
632632
new = similar(dest, typejoin(T, S))
633-
copy!(new, dest)
633+
if new isa AbstractSet
634+
# TODO: merge back these two branches when copy! is re-enabled for sets
635+
union!(new, dest)
636+
else
637+
copy!(new, dest)
638+
end
634639
push!(new, el)
635640
return grow_to!(new, itr, st)
636641
end

base/associative.jl

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -213,15 +213,6 @@ function merge!(combine::Function, d::Associative, others::Associative...)
213213
return d
214214
end
215215

216-
# very similar to `merge!`, but accepts any iterable and extends code
217-
# that would otherwise only use `copy!` with arrays.
218-
function copy!(dest::Union{Associative,AbstractSet}, src)
219-
for x in src
220-
push!(dest, x)
221-
end
222-
return dest
223-
end
224-
225216
"""
226217
keytype(type)
227218

base/deprecated.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2150,6 +2150,9 @@ end
21502150

21512151
@deprecate merge!(repo::LibGit2.GitRepo, args...; kwargs...) LibGit2.merge!(repo, args...; kwargs...)
21522152

2153+
@deprecate copy!(dest::AbstractSet, src) union!(dest, src)
2154+
@deprecate copy!(dest::Associative, src) foldl(push!, dest, src)
2155+
21532156
# END 0.7 deprecations
21542157

21552158
# BEGIN 1.0 deprecations

base/dict.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ function grow_to!(dest::Associative{K,V}, itr, st) where V where K
177177
dest[k] = v
178178
else
179179
new = similar(dest, Pair{typejoin(K,typeof(k)), typejoin(V,typeof(v))})
180-
copy!(new, dest)
180+
merge!(new, dest)
181181
new[k] = v
182182
return grow_to!(new, itr, st)
183183
end

0 commit comments

Comments
 (0)