Skip to content

Commit 2a0184d

Browse files
committed
Merge pull request #16561 from JuliaLang/jb/deprecate_dict_compr
deprecate dict comprehension syntax. fixes #16510
2 parents 35391bf + 879a7f7 commit 2a0184d

File tree

6 files changed

+15
-11
lines changed

6 files changed

+15
-11
lines changed

src/julia-parser.scm

+4-1
Original file line numberDiff line numberDiff line change
@@ -1019,6 +1019,9 @@
10191019
((comprehension)
10201020
(loop (list* 'typed_comprehension ex (cdr al))))
10211021
((dict_comprehension)
1022+
(syntax-deprecation
1023+
s (string #\( (deparse ex) #\) "[a=>b for (a,b) in c]")
1024+
(string (deprecated-dict-replacement ex) "(a=>b for (a,b) in c)"))
10221025
(loop (list* 'typed_dict_comprehension ex (cdr al))))
10231026
(else (error "unknown parse-cat result (internal error)"))))))
10241027
((|.|)
@@ -1995,7 +1998,7 @@
19951998
(syntax-deprecation s "{a for a in b}" "Any[a for a in b]")
19961999
`(typed_comprehension (top Any) ,@(cdr vex)))
19972000
((dict_comprehension)
1998-
(syntax-deprecation s "{a=>b for (a,b) in c}" "Dict{Any,Any}([a=>b for (a,b) in c])")
2001+
(syntax-deprecation s "{a=>b for (a,b) in c}" "Dict{Any,Any}(a=>b for (a,b) in c)")
19992002
`(typed_dict_comprehension (=> (top Any) (top Any)) ,@(cdr vex)))
20002003
((dict)
20012004
(syntax-deprecation s "{a=>b, ...}" "Dict{Any,Any}(a=>b, ...)")

src/julia-syntax.scm

+1
Original file line numberDiff line numberDiff line change
@@ -2016,6 +2016,7 @@
20162016

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

20212022
'typed_dict_comprehension

test/bitarray.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ for m1 = 1 : v1 + 1
515515
@test b == i
516516
b2 = copy(b1)
517517
i2 = copy(i1)
518-
i3 = [j => rand(0:1) for j = 1:v2]
518+
i3 = Dict(j => rand(0:1) for j = 1:v2)
519519
b = splice!(b2, m1:m2, values(i3))
520520
i = splice!(i2, m1:m2, values(i3))
521521
@test isequal(Array(b2), i2)
@@ -545,7 +545,7 @@ for m1 = 1 : v1
545545
@test b == i
546546
b2 = copy(b1)
547547
i2 = copy(i1)
548-
i3 = [j => rand(0:1) for j = 1:v2]
548+
i3 = Dict(j => rand(0:1) for j = 1:v2)
549549
b = splice!(b2, m1:m2, values(i3))
550550
i = splice!(i2, m1:m2, values(i3))
551551
@test isequal(Array(b2), i2)

test/dates/io.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ f2 = "dd/mm/yy"
211211

212212
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)
213213
Dates.MONTHTOVALUEABBR["french"] = french
214-
Dates.VALUETOMONTHABBR["french"] = [v=>k for (k,v) in french]
214+
Dates.VALUETOMONTHABBR["french"] = Dict(v=>k for (k,v) in french)
215215

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

test/dict.jl

+5-5
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,9 @@ end
261261

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

321321
# issue #2540
322-
let d = Dict{Any,Any}([x => 1 for x in ['a', 'b', 'c']])
322+
let d = Dict{Any,Any}(Dict(x => 1 for x in ['a', 'b', 'c']))
323323
@test d == Dict('a'=>1, 'b'=>1, 'c'=> 1)
324324
end
325325

326326
# issue #2629
327-
let d = Dict{AbstractString,AbstractString}([ a => "foo" for a in ["a","b","c"]])
327+
let d = Dict{AbstractString,AbstractString}(Dict( a => "foo" for a in ["a","b","c"]))
328328
@test d == Dict("a"=>"foo","b"=>"foo","c"=>"foo")
329329
end
330330

test/hashing.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ vals = Any[
6767
(1,2,3,4), (1.0,2.0,3.0,4.0), (1,3,2,4),
6868
("a","b"), (SubString("a",1,1), SubString("b",1,1)),
6969
# issue #6900
70-
[x => x for x in 1:10],
70+
Dict(x => x for x in 1:10),
7171
Dict(7=>7,9=>9,4=>4,10=>10,2=>2,3=>3,8=>8,5=>5,6=>6,1=>1),
7272
[], [1], [2], [1, 1], [1, 2], [1, 3], [2, 2], [1, 2, 2], [1, 3, 3],
7373
zeros(2, 2), spzeros(2, 2), eye(2, 2), speye(2, 2),

0 commit comments

Comments
 (0)