Skip to content

Commit 96f64ce

Browse files
authored
deprecate behavior of map on dicts. part of #5794 (#23648)
1 parent 8c2fc37 commit 96f64ce

File tree

4 files changed

+9
-4
lines changed

4 files changed

+9
-4
lines changed

NEWS.md

+3
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,9 @@ Deprecated or removed
428428

429429
* The `Range` abstract type has been renamed to `AbstractRange` ([#23570]).
430430

431+
* `map` on dictionaries previously operated on `key=>value` pairs. This behavior is deprecated,
432+
and in the future `map` will operate only on values ([#5794]).
433+
431434
Command-line option changes
432435
---------------------------
433436

base/abstractarray.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1936,7 +1936,7 @@ function map!(f::F, dest::AbstractArray, A::AbstractArray) where F
19361936
end
19371937

19381938
# map on collections
1939-
map(f, A::Union{AbstractArray,AbstractSet,Associative}) = collect_similar(A, Generator(f,A))
1939+
map(f, A::Union{AbstractArray,AbstractSet}) = collect_similar(A, Generator(f,A))
19401940

19411941
# default to returning an Array for `map` on general iterators
19421942
"""

base/deprecated.jl

+3
Original file line numberDiff line numberDiff line change
@@ -1763,6 +1763,9 @@ import .Iterators.enumerate
17631763

17641764
@deprecate_binding Range AbstractRange
17651765

1766+
# issue #5794
1767+
@deprecate map(f, d::T) where {T<:Associative} T( f(p) for p in pairs(d) )
1768+
17661769
# END 0.7 deprecations
17671770

17681771
# BEGIN 1.0 deprecations

test/dict.jl

+2-3
Original file line numberDiff line numberDiff line change
@@ -429,9 +429,8 @@ d = Dict('a'=>1, 'b'=>1, 'c'=> 3)
429429

430430
# generators, similar
431431
d = Dict(:a=>"a")
432-
@test @inferred(map(identity, d)) == d
433-
@test @inferred(map(p->p.first=>p.second[1], d)) == Dict(:a=>'a')
434-
@test_throws ArgumentError map(p->p.second, d)
432+
# TODO: restore when 0.7 deprecation is removed
433+
#@test @inferred(map(identity, d)) == d
435434

436435
# Issue 12451
437436
@test_throws ArgumentError Dict(0)

0 commit comments

Comments
 (0)