Skip to content

Commit 5957579

Browse files
authored
deprecate merge(::Callable ..) in favor of mergewith (#59775)
after #34296 this method is redundant, and it's also undocumented. according to #43491 (comment), `Callable` should not be used anymore, so it might make sense to remove from `Base` where feasible.
1 parent cd2ebf9 commit 5957579

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

Compiler/test/inference.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3509,11 +3509,11 @@ end
35093509
struct MixedKeyDict{T<:Tuple} #<: AbstractDict{Any,Any}
35103510
dicts::T
35113511
end
3512-
Base.merge(f::Function, d::MixedKeyDict, others::MixedKeyDict...) = _merge(f, (), d.dicts, (d->d.dicts).(others)...)
3513-
Base.merge(f, d::MixedKeyDict, others::MixedKeyDict...) = _merge(f, (), d.dicts, (d->d.dicts).(others)...)
3512+
Base.mergewith(f::Function, d::MixedKeyDict, others::MixedKeyDict...) = _merge(f, (), d.dicts, (d->d.dicts).(others)...)
3513+
Base.mergewith(f, d::MixedKeyDict, others::MixedKeyDict...) = _merge(f, (), d.dicts, (d->d.dicts).(others)...)
35143514
function _merge(f, res, d, others...)
35153515
ofsametype, remaining = _alloftype(Base.heads(d), ((),), others...)
3516-
return _merge(f, (res..., merge(f, ofsametype...)), Base.tail(d), remaining...)
3516+
return _merge(f, (res..., mergewith(f, ofsametype...)), Base.tail(d), remaining...)
35173517
end
35183518
_merge(f, res, ::Tuple{}, others...) = _merge(f, res, others...)
35193519
_merge(f, res, d) = MixedKeyDict((res..., d...))
@@ -3537,9 +3537,9 @@ _alloftype(ofdesiredtype, accumulated) = ofdesiredtype, Base.front(accumulated)
35373537
let
35383538
d = MixedKeyDict((Dict(1 => 3), Dict(4. => 2)))
35393539
e = MixedKeyDict((Dict(1 => 7), Dict(5. => 9)))
3540-
@test merge(+, d, e).dicts == (Dict(1 => 10), Dict(4.0 => 2, 5.0 => 9))
3540+
@test mergewith(+, d, e).dicts == (Dict(1 => 10), Dict(4.0 => 2, 5.0 => 9))
35413541
f = MixedKeyDict((Dict(2 => 7), Dict(5. => 11)))
3542-
@test merge(+, d, e, f).dicts == (Dict(1 => 10, 2 => 7), Dict(4.0 => 2, 5.0 => 20))
3542+
@test mergewith(+, d, e, f).dicts == (Dict(1 => 10, 2 => 7), Dict(4.0 => 2, 5.0 => 20))
35433543
end
35443544

35453545
# Issue #31974

NEWS.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,9 @@ External dependencies
123123
Tooling Improvements
124124
--------------------
125125

126+
Deprecated or removed
127+
---------------------
128+
129+
* The method `merge(combine::Callable, d::AbstractDict...)` is now deprecated to favor `mergewith` instead ([#59775]).
130+
126131
<!--- generated by NEWS-update.jl: -->

base/deprecated.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,3 +566,9 @@ end
566566
to_power_type(x) = oftype(x*x, x)
567567

568568
# END 1.12 deprecations
569+
570+
# BEGIN 1.13 deprecations
571+
572+
@deprecate merge(combine::Callable, d::AbstractDict, others::AbstractDict...) mergewith(combine, d, others...)
573+
574+
# end 1.13 deprecations

test/dict.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,8 +1289,6 @@ struct NonFunctionCallable end
12891289
@test @inferred mergewith(NonFunctionCallable(), d1, d2) == Dict("A" => 1, "B" => 5, "C" => 4)
12901290
@test foldl(mergewith(+), [d1, d2]; init=Dict{Union{},Union{}}()) ==
12911291
Dict("A" => 1, "B" => 5, "C" => 4)
1292-
# backward compatibility
1293-
@test @inferred merge(+, d1, d2) == Dict("A" => 1, "B" => 5, "C" => 4)
12941292
end
12951293

12961294
@testset "Dict merge!" begin

0 commit comments

Comments
 (0)