Skip to content

Commit

Permalink
deprecate dict comprehension syntax. fixes JuliaLang#16510
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed May 24, 2016
1 parent 3bed78c commit 879a7f7
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 11 deletions.
5 changes: 4 additions & 1 deletion src/julia-parser.scm
Original file line number Diff line number Diff line change
Expand Up @@ -1019,6 +1019,9 @@
((comprehension)
(loop (list* 'typed_comprehension ex (cdr al))))
((dict_comprehension)
(syntax-deprecation
s (string #\( (deparse ex) #\) "[a=>b for (a,b) in c]")
(string (deprecated-dict-replacement ex) "(a=>b for (a,b) in c)"))
(loop (list* 'typed_dict_comprehension ex (cdr al))))
(else (error "unknown parse-cat result (internal error)"))))))
((|.|)
Expand Down Expand Up @@ -1995,7 +1998,7 @@
(syntax-deprecation s "{a for a in b}" "Any[a for a in b]")
`(typed_comprehension (top Any) ,@(cdr vex)))
((dict_comprehension)
(syntax-deprecation s "{a=>b for (a,b) in c}" "Dict{Any,Any}([a=>b for (a,b) in c])")
(syntax-deprecation s "{a=>b for (a,b) in c}" "Dict{Any,Any}(a=>b for (a,b) in c)")
`(typed_dict_comprehension (=> (top Any) (top Any)) ,@(cdr vex)))
((dict)
(syntax-deprecation s "{a=>b, ...}" "Dict{Any,Any}(a=>b, ...)")
Expand Down
1 change: 1 addition & 0 deletions src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -2016,6 +2016,7 @@

'dict_comprehension
(lambda (e)
(syntax-deprecation #f "[a=>b for (a,b) in c]" "Dict(a=>b for (a,b) in c)")
(expand-forms (lower-dict-comprehension (cadr e) (cddr e))))

'typed_dict_comprehension
Expand Down
4 changes: 2 additions & 2 deletions test/bitarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ for m1 = 1 : v1 + 1
@test b == i
b2 = copy(b1)
i2 = copy(i1)
i3 = [j => rand(0:1) for j = 1:v2]
i3 = Dict(j => rand(0:1) for j = 1:v2)
b = splice!(b2, m1:m2, values(i3))
i = splice!(i2, m1:m2, values(i3))
@test isequal(Array(b2), i2)
Expand Down Expand Up @@ -545,7 +545,7 @@ for m1 = 1 : v1
@test b == i
b2 = copy(b1)
i2 = copy(i1)
i3 = [j => rand(0:1) for j = 1:v2]
i3 = Dict(j => rand(0:1) for j = 1:v2)
b = splice!(b2, m1:m2, values(i3))
i = splice!(i2, m1:m2, values(i3))
@test isequal(Array(b2), i2)
Expand Down
4 changes: 2 additions & 2 deletions test/dates/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ f2 = "dd/mm/yy"

const french = Dict("janv"=>1,"févr"=>2,"mars"=>3,"avril"=>4,"mai"=>5,"juin"=>6,"juil"=>7,"août"=>8,"sept"=>9,"oct"=>10,"nov"=>11,"déc"=>12)
Dates.MONTHTOVALUEABBR["french"] = french
Dates.VALUETOMONTHABBR["french"] = [v=>k for (k,v) in french]
Dates.VALUETOMONTHABBR["french"] = Dict(v=>k for (k,v) in french)

f = "dd uuuuu yyyy"
@test Dates.Date("28 mai 2014",f;locale="french") == Dates.Date(2014,5,28)
Expand Down Expand Up @@ -240,7 +240,7 @@ f = "duy"
const globex = Dict("f"=>Dates.Jan,"g"=>Dates.Feb,"h"=>Dates.Mar,"j"=>Dates.Apr,"k"=>Dates.May,"m"=>Dates.Jun,
"n"=>Dates.Jul,"q"=>Dates.Aug,"u"=>Dates.Sep,"v"=>Dates.Oct,"x"=>Dates.Nov,"z"=>Dates.Dec)
Dates.MONTHTOVALUEABBR["globex"] = globex
Dates.VALUETOMONTHABBR["globex"] = [v=>uppercase(k) for (k,v) in globex]
Dates.VALUETOMONTHABBR["globex"] = Dict(v=>uppercase(k) for (k,v) in globex)
@test Dates.Date("1F4",f;locale="globex") + Dates.Year(2010) == Dates.Date(2014,1,1)
@test Dates.format(Dates.Date(2014,1,1),f;locale="globex") == "1F4"

Expand Down
10 changes: 5 additions & 5 deletions test/dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,9 @@ end

# show
for d in (Dict("\n" => "\n", "1" => "\n", "\n" => "2"),
[string(i) => i for i = 1:30],
[reshape(1:i^2,i,i) => reshape(1:i^2,i,i) for i = 1:24],
[String(Char['α':'α'+i;]) => String(Char['α':'α'+i;]) for i = (1:10)*10],
Dict(string(i) => i for i = 1:30),
Dict(reshape(1:i^2,i,i) => reshape(1:i^2,i,i) for i = 1:24),
Dict(String(Char['α':'α'+i;]) => String(Char['α':'α'+i;]) for i = (1:10)*10),
Dict("key" => zeros(0, 0)))
for cols in (12, 40, 80), rows in (2, 10, 24)
# Ensure output is limited as requested
Expand Down Expand Up @@ -319,12 +319,12 @@ let sbuff = IOBuffer(),
end

# issue #2540
let d = Dict{Any,Any}([x => 1 for x in ['a', 'b', 'c']])
let d = Dict{Any,Any}(Dict(x => 1 for x in ['a', 'b', 'c']))
@test d == Dict('a'=>1, 'b'=>1, 'c'=> 1)
end

# issue #2629
let d = Dict{AbstractString,AbstractString}([ a => "foo" for a in ["a","b","c"]])
let d = Dict{AbstractString,AbstractString}(Dict( a => "foo" for a in ["a","b","c"]))
@test d == Dict("a"=>"foo","b"=>"foo","c"=>"foo")
end

Expand Down
2 changes: 1 addition & 1 deletion test/hashing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ vals = Any[
(1,2,3,4), (1.0,2.0,3.0,4.0), (1,3,2,4),
("a","b"), (SubString("a",1,1), SubString("b",1,1)),
# issue #6900
[x => x for x in 1:10],
Dict(x => x for x in 1:10),
Dict(7=>7,9=>9,4=>4,10=>10,2=>2,3=>3,8=>8,5=>5,6=>6,1=>1),
[], [1], [2], [1, 1], [1, 2], [1, 3], [2, 2], [1, 2, 2], [1, 3, 3],
zeros(2, 2), spzeros(2, 2), eye(2, 2), speye(2, 2),
Expand Down

0 comments on commit 879a7f7

Please sign in to comment.