Skip to content

Commit

Permalink
remove more deprecations (#28434)
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Aug 5, 2018
1 parent 0f36c69 commit e4d933d
Show file tree
Hide file tree
Showing 27 changed files with 55 additions and 320 deletions.
8 changes: 0 additions & 8 deletions base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@ convert(::Type{T}, a::T) where {T<:AbstractArray} = a
convert(::Type{AbstractArray{T}}, a::AbstractArray) where {T} = AbstractArray{T}(a)
convert(::Type{AbstractArray{T,N}}, a::AbstractArray{<:Any,N}) where {T,N} = AbstractArray{T,N}(a)

if nameof(@__MODULE__) === :Base # avoid method overwrite
# catch undefined constructors before the deprecation kicks in
# TODO: remove when deprecation is removed
function (::Type{T})(arg) where {T<:AbstractArray}
throw(MethodError(T, (arg,)))
end
end

"""
size(A::AbstractArray, [dim])
Expand Down
40 changes: 7 additions & 33 deletions base/abstractdict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -349,14 +349,10 @@ Dict{Int64,String} with 2 entries:
"""
function filter!(f, d::AbstractDict)
badkeys = Vector{keytype(d)}()
try
for pair in d
# don't delete!(d, k) here, since dictionary types
# may not support mutation during iteration
f(pair) || push!(badkeys, pair.first)
end
catch e
return filter!_dict_deprecation(e, f, d)
for pair in d
# don't delete!(d, k) here, since dictionary types
# may not support mutation during iteration
f(pair) || push!(badkeys, pair.first)
end
for k in badkeys
delete!(d, k)
Expand All @@ -365,32 +361,10 @@ function filter!(f, d::AbstractDict)
end

function filter_in_one_pass!(f, d::AbstractDict)
try
for pair in d
if !f(pair)
delete!(d, pair.first)
end
for pair in d
if !f(pair)
delete!(d, pair.first)
end
catch e
return filter!_dict_deprecation(e, f, d)
end
return d
end

function filter!_dict_deprecation(e, f, d::AbstractDict)
if isa(e, MethodError) && e.f === f
depwarn("In `filter!(f, dict)`, `f` is now passed a single pair instead of two arguments.", :filter!)
badkeys = Vector{keytype(d)}()
for (k,v) in d
# don't delete!(d, k) here, since dictionary types
# may not support mutation during iteration
f(k, v) || push!(badkeys, k)
end
for k in badkeys
delete!(d, k)
end
else
rethrow(e)
end
return d
end
Expand Down
12 changes: 2 additions & 10 deletions base/accumulate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,7 @@ julia> cumsum(a, dims=2)
4 9 15
```
"""
function cumsum(A::AbstractArray{T}; dims::Union{Nothing,Integer}=nothing) where T
if dims === nothing
depwarn("`cumsum(A::AbstractArray)` is deprecated, use `cumsum(A, dims=1)` instead.", :cumsum)
dims = 1
end
function cumsum(A::AbstractArray{T}; dims::Integer) where T
out = similar(A, promote_op(add_sum, T, T))
cumsum!(out, A, dims=dims)
end
Expand Down Expand Up @@ -162,11 +158,7 @@ julia> cumprod(a, dims=2)
4 20 120
```
"""
function cumprod(A::AbstractArray; dims::Union{Nothing,Integer}=nothing)
if dims === nothing
depwarn("`cumprod(A::AbstractArray)` is deprecated, use `cumprod(A, dims=1)` instead.", :cumprod)
dims = 1
end
function cumprod(A::AbstractArray; dims::Integer)
return accumulate(mul_prod, A, dims=dims)
end

Expand Down
43 changes: 7 additions & 36 deletions base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1606,14 +1606,8 @@ CartesianIndex(2, 1)
function findnext(A, start)
l = last(keys(A))
i = start
warned = false
while i <= l
a = A[i]
if !warned && !(a isa Bool)
depwarn("In the future `findnext` will only work on boolean collections. Use `findnext(x->x!=0, A, start)` instead.", :findnext)
warned = true
end
if a != 0
if A[i]
return i
end
i = nextind(A, i)
Expand Down Expand Up @@ -1655,13 +1649,8 @@ CartesianIndex(2, 1)
```
"""
function findfirst(A)
warned = false
for (i, a) in pairs(A)
if !warned && !(a isa Bool)
depwarn("In the future `findfirst` will only work on boolean collections. Use `findfirst(x->x!=0, A)` instead.", :findfirst)
warned = true
end
if a != 0
if a
return i
end
end
Expand Down Expand Up @@ -1695,9 +1684,7 @@ julia> findnext(isodd, A, CartesianIndex(1, 1))
CartesianIndex(1, 1)
```
"""
@inline findnext(testf::Function, A, start) = findnext_internal(testf, A, start)

function findnext_internal(testf::Function, A, start)
function findnext(testf::Function, A, start)
l = last(keys(A))
i = start
while i <= l
Expand Down Expand Up @@ -1789,14 +1776,8 @@ CartesianIndex(2, 1)
"""
function findprev(A, start)
i = start
warned = false
while i >= first(keys(A))
a = A[i]
if !warned && !(a isa Bool)
depwarn("In the future `findprev` will only work on boolean collections. Use `findprev(x->x!=0, A, start)` instead.", :findprev)
warned = true
end
a != 0 && return i
A[i] && return i
i = prevind(A, i)
end
return nothing
Expand Down Expand Up @@ -1837,13 +1818,8 @@ CartesianIndex(2, 1)
```
"""
function findlast(A)
warned = false
for (i, a) in Iterators.reverse(pairs(A))
if !warned && !(a isa Bool)
depwarn("In the future `findlast` will only work on boolean collections. Use `findlast(x->x!=0, A)` instead.", :findlast)
warned = true
end
if a != 0
if a
return i
end
end
Expand Down Expand Up @@ -1885,9 +1861,7 @@ julia> findprev(isodd, A, CartesianIndex(1, 2))
CartesianIndex(2, 1)
```
"""
@inline findprev(testf::Function, A, start) = findprev_internal(testf, A, start)

function findprev_internal(testf::Function, A, start)
function findprev(testf::Function, A, start)
i = start
while i >= first(keys(A))
testf(A[i]) && return i
Expand Down Expand Up @@ -2031,10 +2005,7 @@ julia> findall(falses(3))
```
"""
function findall(A)
if !(eltype(A) === Bool) && !all(x -> x isa Bool, A)
depwarn("In the future `findall(A)` will only work on boolean collections. Use `findall(x->x!=0, A)` instead.", :find)
end
collect(first(p) for p in pairs(A) if last(p) != 0)
collect(first(p) for p in pairs(A) if last(p))
end
# Allocating result upfront is faster (possible only when collection can be iterated twice)
function findall(A::AbstractArray{Bool})
Expand Down
4 changes: 0 additions & 4 deletions base/client.jl
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,6 @@ function parse_input_line(s::String; filename::String="none", depwarn=true)
s, sizeof(s), filename, sizeof(filename))
end
end
if ex isa Symbol && all(isequal('_'), string(ex))
# remove with 0.7 deprecation
Meta.lower(Main, ex) # to get possible warning about using _ as an rvalue
end
return ex
end
parse_input_line(s::AbstractString) = parse_input_line(String(s))
Expand Down
4 changes: 2 additions & 2 deletions base/compiler/typeutils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ end
function valid_tparam(@nospecialize(x))
if isa(x, Tuple)
for t in x
isa(t, Symbol) || isbitstype(typeof(t)) || return false
isa(t, Symbol) || isbits(t) || return false
end
return true
end
return isa(x, Symbol) || isbitstype(typeof(x))
return isa(x, Symbol) || isbits(x)
end

# return an upper-bound on type `a` with type `b` removed
Expand Down
2 changes: 1 addition & 1 deletion base/deepcopy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function _deepcopy_array_t(@nospecialize(x), T, stackdict::IdDict)
for i = 1:(length(x)::Int)
if ccall(:jl_array_isassigned, Cint, (Any, Csize_t), x, i-1) != 0
xi = ccall(:jl_arrayref, Any, (Any, Csize_t), x, i-1)
if !isbitstype(typeof(xi))
if !isbits(xi)
xi = deepcopy_internal(xi, stackdict)
end
ccall(:jl_arrayset, Cvoid, (Any, Any, Csize_t), dest, xi, i-1)
Expand Down
75 changes: 0 additions & 75 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,6 @@ end

# BEGIN 0.7 deprecations

# TODO: remove warning for using `_` in parse_input_line in base/client.jl

@deprecate issubtype (<:)

@deprecate union() Set()
Expand Down Expand Up @@ -347,9 +345,6 @@ end

@deprecate momenttype(::Type{T}) where {T} typeof((zero(T)*zero(T) + zero(T)*zero(T))/2) false

# issue #6466
# `write` on non-isbits arrays is deprecated in io.jl.

# PR #23187
@deprecate cpad(s, n::Integer, p=" ") rpad(lpad(s, div(n+textwidth(s), 2), p), n, p) false

Expand Down Expand Up @@ -404,22 +399,6 @@ end
@deprecate (convert(::Type{Integer}, x::Enum{T}) where {T<:Integer}) Integer(x)
@deprecate (convert(::Type{T}, x::Enum{T2}) where {T<:Integer,T2<:Integer}) T(x)

function (::Type{T})(arg) where {T}
if applicable(convert, T, arg)
sig = which(convert, (Type{T}, typeof(arg))).sig
if sig == (Tuple{typeof(convert),Type{S},Number} where S<:Number) ||
sig == (Tuple{typeof(convert),Type{S},AbstractArray} where S<:AbstractArray)
# matches a catch-all converter; will stack overflow
throw(MethodError(T, (arg,)))
end
# if `convert` call would not work, just let the method error happen
depwarn("Constructors no longer fall back to `convert`. A constructor `$T(::$(typeof(arg)))` should be defined instead.", :Type)
end
convert(T, arg)::T
end
# related items to remove in: abstractarray.jl, dates/periods.jl, compiler.jl
# also remove all uses of is_default_method

@deprecate convert(::Type{UInt128}, u::UUID) UInt128(u)
@deprecate convert(::Type{UUID}, s::AbstractString) UUID(s)

Expand All @@ -430,12 +409,6 @@ end
@deprecate rol!(dest, src, i) circshift!(dest, src, -i)
@deprecate rol!(B, i) circshift!(B, -i)

# issue #5148, PR #23259
# warning for `const` on locals should be changed to an error in julia-syntax.scm

# issue #17886
# deprecations for filter[!] with 2-arg functions are in abstractdict.jl

# PR #23066
@deprecate cfunction(f, r, a::Tuple) cfunction(f, r, Tuple{a...})
@noinline function cfunction(f, r, a)
Expand Down Expand Up @@ -487,8 +460,6 @@ end
@deprecate selectperm partialsortperm
@deprecate selectperm! partialsortperm!

# `initialized` keyword arg to `sort` is deprecated in sort.jl

@deprecate promote_noncircular promote false

import .Iterators.enumerate
Expand Down Expand Up @@ -655,18 +626,6 @@ end
@deprecate strwidth textwidth
@deprecate charwidth textwidth

@deprecate find(x::Number) findall(!iszero, x)
@deprecate findnext(A, v, i::Integer) something(findnext(isequal(v), A, i), 0)
@deprecate findfirst(A, v) something(findfirst(isequal(v), A), 0)
@deprecate findprev(A, v, i::Integer) something(findprev(isequal(v), A, i), 0)
@deprecate findlast(A, v) something(findlast(isequal(v), A), 0)
# to fix ambiguities introduced by deprecations
# TODO: also remove find*_internal in array.jl
findnext(pred::Function, A, i::Integer) = findnext_internal(pred, A, i)
findprev(pred::Function, A, i::Integer) = findprev_internal(pred, A, i)
# also remove deprecation warnings in find* functions in array.jl, sparse/sparsematrix.jl,
# and sparse/sparsevector.jl.

# issue #22849
@deprecate reinterpret(::Type{T}, a::Array{S}, dims::NTuple{N,Int}) where {T, S, N} reshape(reinterpret(T, vec(a)), dims)
@deprecate reinterpret(::Type{T}, a::ReinterpretArray{S}, dims::NTuple{N,Int}) where {T, S, N} reshape(reinterpret(T, vec(a)), dims)
Expand Down Expand Up @@ -713,9 +672,6 @@ findprev(pred::Function, A, i::Integer) = findprev_internal(pred, A, i)
@deprecate parse(str::AbstractString, pos::Int, ; kwargs...) Meta.parse(str, pos; kwargs...)
@deprecate_binding ParseError Meta.ParseError

# cumsum and cumprod have deprecations in multidimensional.jl
# when the message is removed, the `dims` keyword argument should become required.

# issue #16307
@deprecate finalizer(o, f::Function) finalizer(f, o)
# This misses other callables but they are very rare in the wild
Expand Down Expand Up @@ -1209,16 +1165,6 @@ end

@deprecate findin(a, b) findall(in(b), a)

@deprecate find findall
@deprecate find(A::AbstractVector) findall(A)
@deprecate find(A::AbstractArray) LinearIndices(A)[findall(A)]
@deprecate find(f::Function, A::AbstractVector) findall(f, A)
@deprecate find(f::Function, A::AbstractArray) LinearIndices(A)[findall(f, A)]

@deprecate findn(x::AbstractVector) (findall(!iszero, x),)
@deprecate findn(x::AbstractMatrix) (I = findall(!iszero, x); (getindex.(I, 1), getindex.(I, 2)))
@deprecate findn(x::AbstractArray{T, N}) where {T, N} (I = findall(!iszero, x); ntuple(i -> getindex.(I, i), N))

@deprecate catch_stacktrace(c_funcs::Bool) stacktrace(catch_backtrace(), c_funcs)
@deprecate catch_stacktrace() stacktrace(catch_backtrace())

Expand Down Expand Up @@ -1413,12 +1359,6 @@ end
# PR #23332
@deprecate ^(x, p::Integer) Base.power_by_squaring(x,p)

# Issue #25979
# The `remove_destination` keyword to `cp`, `mv`, and the unexported `cptree` has been
# renamed to `force`. To remove this deprecation, remove the `remove_destination` keyword
# argument from the function signatures as well as the internal logic that deals with the
# renaming. These live in base/file.jl.

# issue #25928
@deprecate wait(t::Task) fetch(t)

Expand Down Expand Up @@ -1468,10 +1408,6 @@ end

# Issue #25786
@deprecate_binding DevNull devnull
# TODO: When these are removed, also remove the uppercase variants in libuv.jl and stream.jl
@deprecate_binding STDIN stdin true nothing false
@deprecate_binding STDOUT stdout true nothing false
@deprecate_binding STDERR stderr true nothing false

# PR 25062
@deprecate(link_pipe(pipe; julia_only_read = true, julia_only_write = true),
Expand Down Expand Up @@ -1507,9 +1443,6 @@ end
@deprecate(matchall(r::Regex, s::AbstractString; overlap::Bool = false),
collect(m.match for m in eachmatch(r, s, overlap = overlap)))

# remove depwarn for `diff` in multidimensional.jl
# @deprecate diff(A::AbstractMatrix) diff(A, dims=1)

# PR 26194
export assert
function assert(x)
Expand Down Expand Up @@ -1603,14 +1536,6 @@ end

@deprecate linearindices(x::AbstractArray) LinearIndices(x)

# PR #26647
# The `keep` argument in `split` and `rpslit` has been renamed to `keepempty`.
# To remove this deprecation, remove the `keep` argument from the function signatures as well as
# the internal logic that deals with the renaming. These live in base/strings/util.jl.

# when this is removed, `isbitstype(typeof(x))` can be replaced with `isbits(x)`
@deprecate isbits(@nospecialize(t::Type)) isbitstype(t)

# Special string deprecation
@deprecate start(s::AbstractString) firstindex(s)
@deprecate next(s::AbstractString, i::Integer) iterate(s, i)
Expand Down
Loading

0 comments on commit e4d933d

Please sign in to comment.