Skip to content

Commit

Permalink
deprecate copy! for sets and dicts (part of #24808) (#24844)
Browse files Browse the repository at this point in the history
  • Loading branch information
rfourquet committed Dec 15, 2017
1 parent 015ee40 commit a50f6a0
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 12 deletions.
5 changes: 4 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,9 @@ Deprecated or removed

* `num2hex` and `hex2num` have been deprecated in favor of `reinterpret` combined with `parse`/`hex` ([#22088]).

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

* `a:b` is deprecated for constructing a `StepRange` when `a` and `b` have physical units
(Dates and Times). Use `a:s:b`, where `s = Dates.Day(1)` or `s = Dates.Second(1)`.

Expand All @@ -766,7 +769,7 @@ 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]).

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 @@ -3184,6 +3184,10 @@ info(io::IO, err::Exception; prefix="ERROR: ", kw...) =
info(err::Exception; prefix="ERROR: ", kw...) =
info(STDERR, err, prefix=prefix; kw...)

# #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

0 comments on commit a50f6a0

Please sign in to comment.