Skip to content

Commit e91c0ff

Browse files
authored
Deprecate no space between expression and ? in ternaries (#22523)
* Deprecate no space between expression and ? in ternary * Replace uses of expr? in Base
1 parent 2c85595 commit e91c0ff

16 files changed

+40
-38
lines changed

base/cartesian.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ function exprresolve(ex::Expr)
417417
if ex.head == :if
418418
can_eval, tf = exprresolve_conditional(ex.args[1])
419419
if can_eval
420-
ex = tf?ex.args[2]:ex.args[3]
420+
ex = tf ? ex.args[2] : ex.args[3]
421421
end
422422
end
423423
ex

base/docs/utils.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ avgdistance(xs) =
253253
function fuzzyscore(needle, haystack)
254254
score = 0.
255255
is, acro = bestmatch(needle, haystack)
256-
score += (acro?2:1)*length(is) # Matched characters
256+
score += (acro ? 2 : 1)*length(is) # Matched characters
257257
score -= 2(length(needle)-length(is)) # Missing characters
258258
!acro && (score -= avgdistance(is)/10) # Contiguous
259259
!isempty(is) && (score -= mean(is)/100) # Closer to beginning
@@ -330,7 +330,7 @@ function print_joined_cols(io::IO, ss, delim = "", last = delim; cols = displays
330330
total = 0
331331
for i = 1:length(ss)
332332
total += length(ss[i])
333-
total + max(i-2,0)*length(delim) + (i>1?1:0)*length(last) > cols && (i-=1; break)
333+
total + max(i-2,0)*length(delim) + (i>1 ? 1 : 0)*length(last) > cols && (i-=1; break)
334334
end
335335
join(io, ss[1:i], delim, last)
336336
end

base/filesystem.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ include("path.jl")
5252
include("stat.jl")
5353
include("file.jl")
5454
include("poll.jl")
55-
include(string(length(Core.ARGS)>=2?Core.ARGS[2]:"","file_constants.jl")) # include($BUILDROOT/base/file_constants.jl)
55+
include(string(length(Core.ARGS) >= 2 ? Core.ARGS[2] : "", "file_constants.jl")) # include($BUILDROOT/base/file_constants.jl)
5656

5757
## Operations with File (fd) objects ##
5858

base/libc.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ if is_windows()
1010
export GetLastError, FormatMessage
1111
end
1212

13-
include(string(length(Core.ARGS)>=2?Core.ARGS[2]:"","errno_h.jl")) # include($BUILDROOT/base/errno_h.jl)
13+
include(string(length(Core.ARGS) >= 2 ? Core.ARGS[2] : "", "errno_h.jl")) # include($BUILDROOT/base/errno_h.jl)
1414

1515
## RawFD ##
1616

base/libgit2/commit.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
function message(c::GitCommit, raw::Bool=false)
44
local msg_ptr::Cstring
5-
msg_ptr = raw? ccall((:git_commit_message_raw, :libgit2), Cstring, (Ptr{Void},), c.ptr) :
6-
ccall((:git_commit_message, :libgit2), Cstring, (Ptr{Void},), c.ptr)
5+
msg_ptr = raw ? ccall((:git_commit_message_raw, :libgit2), Cstring, (Ptr{Void},), c.ptr) :
6+
ccall((:git_commit_message, :libgit2), Cstring, (Ptr{Void},), c.ptr)
77
if msg_ptr == C_NULL
88
return nothing
99
end

base/libuv.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# Core definitions for interacting with the libuv library from Julia
44

5-
include(string(length(Core.ARGS)>=2?Core.ARGS[2]:"","uv_constants.jl")) # include($BUILDROOT/base/uv_constants.jl)
5+
include(string(length(Core.ARGS) >= 2 ? Core.ARGS[2] : "", "uv_constants.jl")) # include($BUILDROOT/base/uv_constants.jl)
66

77
# convert UV handle data to julia object, checking for null
88
function uv_sizeof_handle(handle)

base/linalg/bidiag.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ julia> Bidiagonal(A, false) #contains the main diagonal and first subdiagonal of
142142
⋅ ⋅ 4 4
143143
```
144144
"""
145-
Bidiagonal(A::AbstractMatrix, isupper::Bool)=Bidiagonal(diag(A), diag(A, isupper?1:-1), isupper)
145+
Bidiagonal(A::AbstractMatrix, isupper::Bool)=Bidiagonal(diag(A), diag(A, isupper ? 1 : -1), isupper)
146146

147147
function getindex(A::Bidiagonal{T}, i::Integer, j::Integer) where T
148148
if !((1 <= i <= size(A,2)) && (1 <= j <= size(A,2)))
@@ -241,7 +241,7 @@ function show(io::IO, M::Bidiagonal)
241241
println(io, summary(M), ":")
242242
print(io, " diag:")
243243
print_matrix(io, (M.dv)')
244-
print(io, M.isupper?"\n super:":"\n sub:")
244+
print(io, M.isupper ? "\n super:" : "\n sub:")
245245
print_matrix(io, (M.ev)')
246246
end
247247

base/linalg/lapack.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,7 @@ for (gels, gesv, getrs, getri, elty) in
867867
(Ptr{UInt8}, Ptr{BlasInt}, Ptr{BlasInt}, Ptr{BlasInt},
868868
Ptr{$elty}, Ptr{BlasInt}, Ptr{$elty}, Ptr{BlasInt},
869869
Ptr{$elty}, Ptr{BlasInt}, Ptr{BlasInt}),
870-
&(btrn?'T':'N'), &m, &n, &size(B,2), A, &max(1,stride(A,2)),
870+
&(btrn ? 'T' : 'N'), &m, &n, &size(B,2), A, &max(1,stride(A,2)),
871871
B, &max(1,stride(B,2)), work, &lwork, info)
872872
chklapackerror(info[])
873873
if i == 1

base/linalg/triangular.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ end
372372
function copy!(A::T, B::T) where T<:Union{UpperTriangular,UnitUpperTriangular}
373373
n = size(B,1)
374374
for j = 1:n
375-
for i = 1:(isa(B, UnitUpperTriangular)?j-1:j)
375+
for i = 1:(isa(B, UnitUpperTriangular) ? j-1 : j)
376376
@inbounds A[i,j] = B[i,j]
377377
end
378378
end
@@ -381,7 +381,7 @@ end
381381
function copy!(A::T, B::T) where T<:Union{LowerTriangular,UnitLowerTriangular}
382382
n = size(B,1)
383383
for j = 1:n
384-
for i = (isa(B, UnitLowerTriangular)?j+1:j):n
384+
for i = (isa(B, UnitLowerTriangular) ? j+1 : j):n
385385
@inbounds A[i,j] = B[i,j]
386386
end
387387
end
@@ -394,7 +394,7 @@ function scale!(A::UpperTriangular, B::Union{UpperTriangular,UnitUpperTriangular
394394
if isa(B, UnitUpperTriangular)
395395
@inbounds A[j,j] = c
396396
end
397-
for i = 1:(isa(B, UnitUpperTriangular)?j-1:j)
397+
for i = 1:(isa(B, UnitUpperTriangular) ? j-1 : j)
398398
@inbounds A[i,j] = c * B[i,j]
399399
end
400400
end
@@ -406,7 +406,7 @@ function scale!(A::LowerTriangular, B::Union{LowerTriangular,UnitLowerTriangular
406406
if isa(B, UnitLowerTriangular)
407407
@inbounds A[j,j] = c
408408
end
409-
for i = (isa(B, UnitLowerTriangular)?j+1:j):n
409+
for i = (isa(B, UnitLowerTriangular) ? j+1 : j):n
410410
@inbounds A[i,j] = c * B[i,j]
411411
end
412412
end

base/pcre.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
module PCRE
66

7-
include(string(length(Core.ARGS)>=2?Core.ARGS[2]:"","pcre_h.jl")) # include($BUILDROOT/base/pcre_h.jl)
7+
include(string(length(Core.ARGS) >= 2 ? Core.ARGS[2] : "", "pcre_h.jl")) # include($BUILDROOT/base/pcre_h.jl)
88

99
const PCRE_LIB = "libpcre2-8"
1010

base/printf.jl

+12-12
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,8 @@ function gen_d(flags::String, width::Int, precision::Int, c::Char)
299299
push!(blk.args, pad(width-precision, padding, ' '))
300300
end
301301
# print sign
302-
'+' in flags ? push!(blk.args, :(write(out, neg?'-':'+'))) :
303-
' ' in flags ? push!(blk.args, :(write(out, neg?'-':' '))) :
302+
'+' in flags ? push!(blk.args, :(write(out, neg ? '-' : '+'))) :
303+
' ' in flags ? push!(blk.args, :(write(out, neg ? '-' : ' '))) :
304304
push!(blk.args, :(neg && write(out, '-')))
305305
# print prefix
306306
for ch in prefix
@@ -362,8 +362,8 @@ function gen_f(flags::String, width::Int, precision::Int, c::Char)
362362
push!(blk.args, pad(width-1, padding, ' '))
363363
end
364364
# print sign
365-
'+' in flags ? push!(blk.args, :(write(out, neg?'-':'+'))) :
366-
' ' in flags ? push!(blk.args, :(write(out, neg?'-':' '))) :
365+
'+' in flags ? push!(blk.args, :(write(out, neg ? '-' : '+'))) :
366+
' ' in flags ? push!(blk.args, :(write(out, neg ? '-' : ' '))) :
367367
push!(blk.args, :(neg && write(out, '-')))
368368
# print zero padding
369369
if padding !== nothing && !('-' in flags) && '0' in flags
@@ -456,8 +456,8 @@ function gen_e(flags::String, width::Int, precision::Int, c::Char, inside_g::Boo
456456
push!(blk.args, pad(width, padding, ' '))
457457
end
458458
# print sign
459-
'+' in flags ? push!(blk.args, :(write(out, neg?'-':'+'))) :
460-
' ' in flags ? push!(blk.args, :(write(out, neg?'-':' '))) :
459+
'+' in flags ? push!(blk.args, :(write(out, neg ? '-' : '+'))) :
460+
' ' in flags ? push!(blk.args, :(write(out, neg ? '-' : ' '))) :
461461
push!(blk.args, :(neg && write(out, '-')))
462462
# print zero padding
463463
if padding !== nothing && !('-' in flags) && '0' in flags
@@ -554,16 +554,16 @@ function gen_a(flags::String, width::Int, precision::Int, c::Char)
554554
if '#' in flags
555555
padding = :($padding - (len-1))
556556
else
557-
padding = :($padding - (len>1?len:0))
557+
padding = :($padding - (len>1 ? len : 0))
558558
end
559559
end
560560
# print space padding
561561
if padding !== nothing && !('-' in flags) && !('0' in flags)
562562
push!(blk.args, pad(width, padding, ' '))
563563
end
564564
# print sign
565-
'+' in flags ? push!(blk.args, :(write(out, neg?'-':'+'))) :
566-
' ' in flags ? push!(blk.args, :(write(out, neg?'-':' '))) :
565+
'+' in flags ? push!(blk.args, :(write(out, neg ? '-' : '+'))) :
566+
' ' in flags ? push!(blk.args, :(write(out, neg ? '-' : ' '))) :
567567
push!(blk.args, :(neg && write(out, '-')))
568568
# hex prefix
569569
for ch in hexmark
@@ -630,7 +630,7 @@ function _limit(s, prec)
630630
prec >= sizeof(s) && return s
631631
p = prevind(s, prec+1)
632632
n = nextind(s, p)-1
633-
s[1:(prec>=n?n:prevind(s,p))]
633+
s[1:(prec>=n ? n : prevind(s,p))]
634634
end
635635

636636
function gen_s(flags::String, width::Int, precision::Int, c::Char)
@@ -755,8 +755,8 @@ function gen_g(flags::String, width::Int, precision::Int, c::Char)
755755
$padexpr; end))
756756
end
757757
# print sign
758-
'+' in flags ? push!(blk.args, :(write(out, neg?'-':'+'))) :
759-
' ' in flags ? push!(blk.args, :(write(out, neg?'-':' '))) :
758+
'+' in flags ? push!(blk.args, :(write(out, neg ? '-' : '+'))) :
759+
' ' in flags ? push!(blk.args, :(write(out, neg ? '-' : ' '))) :
760760
push!(blk.args, :(neg && write(out, '-')))
761761
# print zero padding
762762
if !('-' in flags) && '0' in flags

base/sparse/linalg.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ function normestinv(A::SparseMatrixCSC{T}, t::Integer = min(2,maximum(size(A))))
586586

587587
function _rand_pm1!(v)
588588
for i in eachindex(v)
589-
v[i] = rand()<0.5?1:-1
589+
v[i] = rand()<0.5 ? 1 : -1
590590
end
591591
end
592592

@@ -643,7 +643,7 @@ function normestinv(A::SparseMatrixCSC{T}, t::Integer = min(2,maximum(size(A))))
643643
S_old = copy(S)
644644
for j = 1:t
645645
for i = 1:n
646-
S[i,j] = Y[i,j]==0?one(Y[i,j]):sign(Y[i,j])
646+
S[i,j] = Y[i,j]==0 ? one(Y[i,j]) : sign(Y[i,j])
647647
end
648648
end
649649

src/julia-parser.scm

+3-1
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,9 @@
734734
(define (parse-cond s)
735735
(let ((ex (parse-arrow s)))
736736
(cond ((eq? (peek-token s) '?)
737-
(begin (take-token s)
737+
(begin (if (not (ts:space? s))
738+
(syntax-deprecation s (string (deparse ex) "?") (string (deparse ex) " ?")))
739+
(take-token s)
738740
(let ((then (without-range-colon (parse-eq* s))))
739741
(if (not (eq? (take-token s) ':))
740742
(error "colon expected in \"?\" expression")

test/broadcast.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ end
200200

201201
# issue #4883
202202
@test isa(broadcast(tuple, [1 2 3], ["a", "b", "c"]), Matrix{Tuple{Int,String}})
203-
@test isa(broadcast((x,y)->(x==1?1.0:x,y), [1 2 3], ["a", "b", "c"]), Matrix{Tuple{Real,String}})
203+
@test isa(broadcast((x,y)->(x==1 ? 1.0 : x, y), [1 2 3], ["a", "b", "c"]), Matrix{Tuple{Real,String}})
204204
let a = length.(["foo", "bar"])
205205
@test isa(a, Vector{Int})
206206
@test a == [3, 3]

test/distributed_exec.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -902,9 +902,9 @@ function testmap_equivalence(f, c...)
902902
end
903903

904904
testmap_equivalence(identity, (1,2,3,4))
905-
testmap_equivalence(x->x>0?1.0:0.0, sparse(eye(5)))
905+
testmap_equivalence(x->x>0 ? 1.0 : 0.0, sparse(eye(5)))
906906
testmap_equivalence((x,y,z)->x+y+z, 1,2,3)
907-
testmap_equivalence(x->x?false:true, BitArray(10,10))
907+
testmap_equivalence(x->x ? false : true, BitArray(10,10))
908908
testmap_equivalence(x->"foobar", BitArray(10,10))
909909
testmap_equivalence((x,y,z)->string(x,y,z), BitArray(10), ones(10), "1234567890")
910910

test/linalg/bidiag.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,12 @@ srand(1)
8484
@testset "Constructor and basic properties" begin
8585
@test size(T, 1) == size(T, 2) == n
8686
@test size(T) == (n, n)
87-
@test Array(T) == diagm(dv) + diagm(ev, isupper?1:-1)
87+
@test Array(T) == diagm(dv) + diagm(ev, isupper ? 1 : -1)
8888
@test Bidiagonal(Array(T), isupper) == T
8989
@test big.(T) == T
90-
@test Array(abs.(T)) == abs.(diagm(dv)) + abs.(diagm(ev, isupper?1:-1))
91-
@test Array(real(T)) == real(diagm(dv)) + real(diagm(ev, isupper?1:-1))
92-
@test Array(imag(T)) == imag(diagm(dv)) + imag(diagm(ev, isupper?1:-1))
90+
@test Array(abs.(T)) == abs.(diagm(dv)) + abs.(diagm(ev, isupper ? 1 : -1))
91+
@test Array(real(T)) == real(diagm(dv)) + real(diagm(ev, isupper ? 1 : -1))
92+
@test Array(imag(T)) == imag(diagm(dv)) + imag(diagm(ev, isupper ? 1 : -1))
9393
end
9494
z = zeros(elty, n)
9595

0 commit comments

Comments
 (0)