Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deprecate copy! for sets and dicts (part of #24808) #24844

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -758,10 +758,14 @@ Deprecated or removed
in the new `Unicode` standard library module ([#25021]).

* The aliases `Complex32`, `Complex64` and `Complex128` have been deprecated in favor of `ComplexF16`,
`ComplexF32` and `ComplexF64` respectively (#24647).
`ComplexF32` and `ComplexF64` respectively ([#24647]).

* `Associative` has been deprecated in favor of `AbstractDict` ([#25012]).

* `copy!` is deprecated for `AbstractSet` and `AbstractDict`, with the intention to re-enable
it with a cleaner meaning in a future version ([#24844]).

>>>>>>> deprecate copy! for sets and dicts (part of #24808)
Command-line option changes
---------------------------

Expand Down
9 changes: 0 additions & 9 deletions base/abstractdict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -230,15 +230,6 @@ function merge!(combine::Function, d::AbstractDict, others::AbstractDict...)
return d
end

# very similar to `merge!`, but accepts any iterable and extends code
# that would otherwise only use `copy!` with arrays.
function copy!(dest::Union{AbstractDict,AbstractSet}, src)
for x in src
push!(dest, x)
end
return dest
end

"""
keytype(type)

Expand Down
7 changes: 6 additions & 1 deletion base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,12 @@ function grow_to!(dest, itr, st)
push!(dest, el::T)
else
new = similar(dest, typejoin(T, S))
copy!(new, dest)
if new isa AbstractSet
# TODO: merge back these two branches when copy! is re-enabled for sets
union!(new, dest)
else
copy!(new, dest)
end
push!(new, el)
return grow_to!(new, itr, st)
end
Expand Down
4 changes: 4 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2984,6 +2984,10 @@ end

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

# #24844
@deprecate copy!(dest::AbstractSet, src) union!(dest, src)
@deprecate copy!(dest::AbstractDict, src) foldl(push!, dest, src)

# issue #24019
@deprecate similar(a::AbstractDict) empty(a)
@deprecate similar(a::AbstractDict, ::Type{Pair{K,V}}) where {K, V} empty(a, K, V)
Expand Down
2 changes: 1 addition & 1 deletion base/dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ function grow_to!(dest::AbstractDict{K,V}, itr, st) where V where K
dest[k] = v
else
new = empty(dest, typejoin(K,typeof(k)), typejoin(V,typeof(v)))
copy!(new, dest)
merge!(new, dest)
new[k] = v
return grow_to!(new, itr, st)
end
Expand Down