diff --git a/base/deprecated.jl b/base/deprecated.jl index e44deb1f41054..1d2b29a697ca2 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -290,7 +290,7 @@ module DFT export FFTW end using .DFT -for f in filter(s -> isexported(DFT, s), names(DFT, true)) +for f in filter(s -> isexported(DFT, s), names(DFT, all = true)) @eval export $f end module DSP @@ -495,14 +495,14 @@ end # PR #22088 function hex2num(s::AbstractString) - depwarn("`hex2num(s)` is deprecated. Use `reinterpret(Float64, parse(UInt64, s, 16))` instead.", :hex2num) + depwarn("`hex2num(s)` is deprecated. Use `reinterpret(Float64, parse(UInt64, s, base = 16))` instead.", :hex2num) if length(s) <= 4 - return reinterpret(Float16, parse(UInt16, s, 16)) + return reinterpret(Float16, parse(UInt16, s, base = 16)) end if length(s) <= 8 - return reinterpret(Float32, parse(UInt32, s, 16)) + return reinterpret(Float32, parse(UInt32, s, base = 16)) end - return reinterpret(Float64, parse(UInt64, s, 16)) + return reinterpret(Float64, parse(UInt64, s, base = 16)) end export hex2num @@ -1582,7 +1582,8 @@ end @deprecate catch_stacktrace(c_funcs::Bool) stacktrace(catch_backtrace(), c_funcs) @deprecate catch_stacktrace() stacktrace(catch_backtrace()) -@deprecate method_exists hasmethod +@deprecate method_exists(f, t) hasmethod(f, t) +@deprecate method_exists(f, t, world) hasmethod(f, t, world = world) @deprecate object_id objectid @@ -1631,6 +1632,24 @@ export readandwrite @deprecate indmin argmin @deprecate indmax argmax +@deprecate Timer(timeout, repeat) Timer(timeout, interval = repeat) +@deprecate Timer(callback, delay, repeat) Time(callback, delay, interval = repeat) +@deprecate names(m, all) names(m, all = all) +@deprecate names(m, all, imported) names(m, all = all, imported = imported) +@deprecate code_native(io, f, types, syntax) code_native(io, f, types, syntax = syntax) +@deprecate code_native(f, types, syntax) code_native(f, types, syntax = syntax) +@deprecate eachmatch(re, str, overlap) eachmatch(re, str, overlap = overlap) +@deprecate matchall(re, str, overlap) matchall(re, str, overlap = overlap) +@deprecate chop(s, head) chop(s, head = head) +@deprecate chop(s, head, tail) chop(s, head = head, tail = tail) +@deprecate tryparse(T::Type{<:Integer}, s, base) tryparse(T, s, base = base) +@deprecate parse(T::Type{<:Integer}, s, base) parse(T, s, base = base) +@eval Filesystem @deprecate mkdir(path, mode) mkdir(path, mode = mode) +@eval Filesystem @deprecate mkpath(path, mode) mkpath(path, mode = mode) +@deprecate countlines(x, eol) countlines(x, eol = eol) +@deprecate PipeBuffer(data, maxsize) PipeBuffer(data, maxsize = maxsize) +@deprecate unsafe_wrap(T, pointer, dims, own) unsafe_wrap(T, pointer, dims, own = own) + # END 0.7 deprecations # BEGIN 1.0 deprecations diff --git a/base/docs/utils.jl b/base/docs/utils.jl index b42fc3dbdead3..0ae186f5ea1d9 100644 --- a/base/docs/utils.jl +++ b/base/docs/utils.jl @@ -369,7 +369,7 @@ moduleusings(mod) = ccall(:jl_module_usings, Any, (Any,), mod) filtervalid(names) = filter(x->!contains(x, r"#"), map(string, names)) accessible(mod::Module) = - [filter!(s -> !Base.isdeprecated(mod, s), names(mod, true, true)); + [filter!(s -> !Base.isdeprecated(mod, s), names(mod, all = true, imported = true)); map(names, moduleusings(mod))...; builtins] |> unique |> filtervalid diff --git a/base/errorshow.jl b/base/errorshow.jl index b4b579c0cc87d..de9f53fffb37f 100644 --- a/base/errorshow.jl +++ b/base/errorshow.jl @@ -234,7 +234,7 @@ function showerror(io::IO, ex::MethodError) end end if (ex.world != typemax(UInt) && hasmethod(ex.f, arg_types) && - !hasmethod(ex.f, arg_types, ex.world)) + !hasmethod(ex.f, arg_types, world = ex.world)) curworld = ccall(:jl_get_world_counter, UInt, ()) println(io) print(io, "The applicable method may be too new: running in world age $(ex.world), while current world is $(curworld).") diff --git a/base/event.jl b/base/event.jl index 92ae58248ebbb..8263fdb5e8e49 100644 --- a/base/event.jl +++ b/base/event.jl @@ -341,12 +341,12 @@ end ## timer-based notifications """ - Timer(delay, repeat=0) + Timer(delay; interval = 0) Create a timer that wakes up tasks waiting for it (by calling [`wait`](@ref) on the timer object). Waiting tasks are woken after an intial delay of `delay` seconds, and then repeating with the given -`repeat` interval in seconds. If `repeat` is equal to `0`, the timer is only triggered once. When +`interval` in seconds. If `interval` is equal to `0`, the timer is only triggered once. When the timer is closed (by [`close`](@ref) waiting tasks are woken with an error. Use [`isopen`](@ref) to check whether a timer is still active. """ @@ -355,9 +355,9 @@ mutable struct Timer cond::Condition isopen::Bool - function Timer(timeout::Real, repeat::Real=0.0) + function Timer(timeout::Real; interval::Real = 0.0) timeout ≥ 0 || throw(ArgumentError("timer cannot have negative timeout of $timeout seconds")) - repeat ≥ 0 || throw(ArgumentError("timer cannot have negative repeat interval of $repeat seconds")) + interval ≥ 0 || throw(ArgumentError("timer cannot have negative repeat interval of $interval seconds")) this = new(Libc.malloc(_sizeof_uv_timer), Condition(), true) err = ccall(:uv_timer_init, Cint, (Ptr{Cvoid}, Ptr{Cvoid}), eventloop(), this) @@ -374,7 +374,7 @@ mutable struct Timer ccall(:uv_update_time, Cvoid, (Ptr{Cvoid},), eventloop()) ccall(:uv_timer_start, Cint, (Ptr{Cvoid}, Ptr{Cvoid}, UInt64, UInt64), this, uv_jl_timercb::Ptr{Cvoid}, - UInt64(round(timeout * 1000)) + 1, UInt64(round(repeat * 1000))) + UInt64(round(timeout * 1000)) + 1, UInt64(round(interval * 1000))) return this end end @@ -444,13 +444,13 @@ end # timer with repeated callback """ - Timer(callback::Function, delay, repeat=0) + Timer(callback::Function, delay; interval = 0) Create a timer that wakes up tasks waiting for it (by calling [`wait`](@ref) on the timer object) and calls the function `callback`. Waiting tasks are woken and the function `callback` is called after an intial delay of `delay` seconds, -and then repeating with the given `repeat` interval in seconds. If `repeat` is equal to `0`, the timer +and then repeating with the given `interval` in seconds. If `interval` is equal to `0`, the timer is only triggered once. The function `callback` is called with a single argument, the timer itself. When the timer is closed (by [`close`](@ref) waiting tasks are woken with an error. Use [`isopen`](@ref) to check whether a timer is still active. @@ -463,7 +463,7 @@ Here the first number is printed after a delay of two seconds, then the followin julia> begin i = 0 cb(timer) = (global i += 1; println(i)) - t = Timer(cb, 2, 0.2) + t = Timer(cb, 2, interval = 0.2) wait(t) sleep(0.5) close(t) @@ -473,8 +473,8 @@ julia> begin 3 ``` """ -function Timer(cb::Function, timeout::Real, repeat::Real=0.0) - t = Timer(timeout, repeat) +function Timer(cb::Function, timeout::Real; interval::Real = 0.0) + t = Timer(timeout, interval = interval) waiter = Task(function() while isopen(t) success = try diff --git a/base/file.jl b/base/file.jl index 104e8cc411d2d..60721ba3e38cf 100644 --- a/base/file.jl +++ b/base/file.jl @@ -81,8 +81,15 @@ Temporarily changes the current working directory and applies function `f` befor """ cd(f::Function) = cd(f, homedir()) +function checkmode(mode::Integer) + if !(0 <= mode <= 511) + throw(ArgumentError("Mode must be between 0 and 511 = 0o777")) + end + mode +end + """ - mkdir(path::AbstractString, mode::Unsigned=0o777) + mkdir(path::AbstractString; mode::Unsigned = 0o777) Make a new directory with name `path` and permissions `mode`. `mode` defaults to `0o777`, modified by the current file creation mask. This function never creates more than one @@ -90,28 +97,28 @@ directory. If the directory already exists, or some intermediate directories do this function throws an error. See [`mkpath`](@ref) for a function which creates all required intermediate directories. """ -function mkdir(path::AbstractString, mode::Unsigned=0o777) +function mkdir(path::AbstractString; mode::Integer = 0o777) @static if Sys.iswindows() ret = ccall(:_wmkdir, Int32, (Cwstring,), path) else - ret = ccall(:mkdir, Int32, (Cstring, UInt32), path, mode) + ret = ccall(:mkdir, Int32, (Cstring, UInt32), path, checkmode(mode)) end systemerror(:mkdir, ret != 0; extrainfo=path) end """ - mkpath(path::AbstractString, mode::Unsigned=0o777) + mkpath(path::AbstractString; mode::Unsigned = 0o777) Create all directories in the given `path`, with permissions `mode`. `mode` defaults to `0o777`, modified by the current file creation mask. """ -function mkpath(path::AbstractString, mode::Unsigned=0o777) +function mkpath(path::AbstractString; mode::Integer = 0o777) isdirpath(path) && (path = dirname(path)) dir = dirname(path) (path == dir || isdir(path)) && return - mkpath(dir, mode) + mkpath(dir, mode = checkmode(mode)) try - mkdir(path, mode) + mkdir(path, mode = mode) # If there is a problem with making the directory, but the directory # does in fact exist, then ignore the error. Else re-throw it. catch err @@ -123,9 +130,6 @@ function mkpath(path::AbstractString, mode::Unsigned=0o777) end end -mkdir(path::AbstractString, mode::Signed) = throw(ArgumentError("mode must be an unsigned integer; try 0o$mode")) -mkpath(path::AbstractString, mode::Signed) = throw(ArgumentError("mode must be an unsigned integer; try 0o$mode")) - """ rm(path::AbstractString; force::Bool=false, recursive::Bool=false) diff --git a/base/intfuncs.jl b/base/intfuncs.jl index 3a98e9edd876a..906f9012cb07a 100644 --- a/base/intfuncs.jl +++ b/base/intfuncs.jl @@ -747,7 +747,7 @@ bitstring(x::Union{Int64,UInt64,Float64}) = bin(reinterpret(UInt64,x),64) bitstring(x::Union{Int128,UInt128}) = bin(reinterpret(UInt128,x),128) """ - digits([T<:Integer], n::Integer, base::T=10, pad::Integer=1) + digits([T<:Integer], n::Integer; base::T = 10, pad::Integer = 1) Return an array with element type `T` (default `Int`) of the digits of `n` in the given base, optionally padded with zeros to a specified size. More significant digits are at @@ -755,19 +755,19 @@ higher indices, such that `n == sum([digits[k]*base^(k-1) for k=1:length(digits) # Examples ```jldoctest -julia> digits(10, 10) +julia> digits(10, base = 10) 2-element Array{Int64,1}: 0 1 -julia> digits(10, 2) +julia> digits(10, base = 2) 4-element Array{Int64,1}: 0 1 0 1 -julia> digits(10, 2, 6) +julia> digits(10, base = 2, pad = 6) 6-element Array{Int64,1}: 0 1 @@ -777,10 +777,11 @@ julia> digits(10, 2, 6) 0 ``` """ -digits(n::Integer, base::T=10, pad::Integer=1) where {T<:Integer} = digits(T, n, base, pad) +digits(n::Integer; base = base::Integer = 10, pad = pad::Integer = 1) = + digits(typeof(base), n, base = base, pad = pad) -function digits(T::Type{<:Integer}, n::Integer, base::Integer=10, pad::Integer=1) - digits!(zeros(T, ndigits(n, base, pad)), n, base) +function digits(T::Type{<:Integer}, n::Integer; base::Integer = 10, pad::Integer = 1) + digits!(zeros(T, ndigits(n, base, pad)), n, base = base) end """ @@ -792,7 +793,7 @@ hastypemax(::Base.BitIntegerType) = true hastypemax(::Type{T}) where {T} = applicable(typemax, T) """ - digits!(array, n::Integer, base::Integer=10) + digits!(array, n::Integer; base::Integer = 10) Fills an array of the digits of `n` in the given base. More significant digits are at higher indices. If the array length is insufficient, the least significant digits are filled up to @@ -800,14 +801,14 @@ the array length. If the array length is excessive, the excess portion is filled # Examples ```jldoctest -julia> digits!([2,2,2,2], 10, 2) +julia> digits!([2,2,2,2], 10, base = 2) 4-element Array{Int64,1}: 0 1 0 1 -julia> digits!([2,2,2,2,2,2], 10, 2) +julia> digits!([2,2,2,2,2,2], 10, base = 2) 6-element Array{Int64,1}: 0 1 @@ -817,8 +818,8 @@ julia> digits!([2,2,2,2,2,2], 10, 2) 0 ``` """ -function digits!(a::AbstractVector{T}, n::Integer, base::Integer=10) where T<:Integer - base < 0 && isa(n, Unsigned) && return digits!(a, convert(Signed, n), base) +function digits!(a::AbstractVector{T}, n::Integer; base::Integer = 10) where T<:Integer + base < 0 && isa(n, Unsigned) && return digits!(a, convert(Signed, n), base = base) 2 <= abs(base) || throw(ArgumentError("base must be ≥ 2 or ≤ -2, got $base")) hastypemax(T) && abs(base) - 1 > typemax(T) && throw(ArgumentError("type $T too small for base $base")) diff --git a/base/io.jl b/base/io.jl index 13dd90446ad9f..d9d598df13737 100644 --- a/base/io.jl +++ b/base/io.jl @@ -975,7 +975,7 @@ function skipchars(predicate, io::IO; linecomment=nothing) end """ - countlines(io::IO, eol::Char='\\n') + countlines(io::IO; eol::Char = '\\n') Read `io` until the end of the stream/file and count the number of lines. To specify a file pass the filename as the first argument. EOL markers other than `'\\n'` are supported by @@ -993,11 +993,11 @@ julia> io = IOBuffer("JuliaLang is a GitHub organization."); julia> countlines(io) 0 -julia> countlines(io, '.') +julia> countlines(io, eol = '.') 1 ``` """ -function countlines(io::IO, eol::Char='\n') +function countlines(io::IO; eol::Char='\n') isascii(eol) || throw(ArgumentError("only ASCII line terminators are supported")) aeol = UInt8(eol) a = Vector{UInt8}(uninitialized, 8192) @@ -1011,4 +1011,4 @@ function countlines(io::IO, eol::Char='\n') nl end -countlines(f::AbstractString, eol::Char='\n') = open(io->countlines(io,eol), f)::Int +countlines(f::AbstractString; eol::Char = '\n') = open(io->countlines(io, eol = eol), f)::Int diff --git a/base/iobuffer.jl b/base/iobuffer.jl index 4af144d824f89..a41bb4fe74590 100644 --- a/base/iobuffer.jl +++ b/base/iobuffer.jl @@ -115,7 +115,7 @@ IOBuffer(maxsize::Integer) = (x=IOBuffer(StringVector(maxsize), true, true, maxs # PipeBuffers behave like Unix Pipes. They are typically readable and writable, they act appendable, and are not seekable. """ - PipeBuffer(data::Vector{UInt8}=UInt8[],[maxsize::Integer=typemax(Int)]) + PipeBuffer(data::Vector{UInt8}=UInt8[]; maxsize::Integer = typemax(Int)) An [`IOBuffer`](@ref) that allows reading and performs writes by appending. Seeking and truncating are not supported. @@ -123,9 +123,9 @@ See [`IOBuffer`](@ref) for the available constructors. If `data` is given, creates a `PipeBuffer` to operate on a data vector, optionally specifying a size beyond which the underlying `Array` may not be grown. """ -PipeBuffer(data::Vector{UInt8}=UInt8[], maxsize::Int=typemax(Int)) = +PipeBuffer(data::Vector{UInt8}=UInt8[]; maxsize::Int = typemax(Int)) = GenericIOBuffer(data,true,true,false,true,maxsize) -PipeBuffer(maxsize::Integer) = (x = PipeBuffer(StringVector(maxsize),maxsize); x.size=0; x) +PipeBuffer(maxsize::Integer) = (x = PipeBuffer(StringVector(maxsize), maxsize = maxsize); x.size=0; x) function copy(b::GenericIOBuffer) ret = typeof(b)(b.writable ? copy(b.data) : b.data, diff --git a/base/libgit2/blob.jl b/base/libgit2/blob.jl index c2186765c2ce1..d306ab96924bf 100644 --- a/base/libgit2/blob.jl +++ b/base/libgit2/blob.jl @@ -19,7 +19,7 @@ is binary and not valid Unicode. """ function rawcontent(blob::GitBlob) ptr = ccall((:git_blob_rawcontent, :libgit2), Ptr{UInt8}, (Ptr{Cvoid},), blob.ptr) - copy(unsafe_wrap(Array, ptr, (length(blob),), false)) + copy(unsafe_wrap(Array, ptr, (length(blob),), own = false)) end """ diff --git a/base/loading.jl b/base/loading.jl index 27fc4c2e82820..44104f658a4e3 100644 --- a/base/loading.jl +++ b/base/loading.jl @@ -1104,7 +1104,7 @@ function create_expr_cache(input::String, output::String, concrete_deps::typeof( close(in) catch ex close(in) - process_running(io) && Timer(t -> kill(io), 5.0) # wait a short time before killing the process to give it a chance to clean up on its own first + process_running(io) && Timer(t -> kill(io), interval = 5.0) # wait a short time before killing the process to give it a chance to clean up on its own first rethrow(ex) end return io diff --git a/base/mpfr.jl b/base/mpfr.jl index a77c68c46ed04..b983fc1172ceb 100644 --- a/base/mpfr.jl +++ b/base/mpfr.jl @@ -131,8 +131,8 @@ BigFloat(x::Union{UInt8,UInt16,UInt32}) = BigFloat(convert(Culong, x)) BigFloat(x::Union{Float16,Float32}) = BigFloat(Float64(x)) BigFloat(x::Rational) = BigFloat(numerator(x)) / BigFloat(denominator(x)) -function tryparse(::Type{BigFloat}, s::AbstractString, base::Int=0) - !isempty(s) && isspace(s[end]) && return tryparse(BigFloat, rstrip(s), base) +function tryparse(::Type{BigFloat}, s::AbstractString; base::Integer = 0) + !isempty(s) && isspace(s[end]) && return tryparse(BigFloat, rstrip(s), base = base) z = BigFloat() err = ccall((:mpfr_set_str, :libmpfr), Int32, (Ref{BigFloat}, Cstring, Int32, Int32), z, s, base, ROUNDING_MODE[]) err == 0 ? z : nothing diff --git a/base/parse.jl b/base/parse.jl index cf461142dba61..d17514ede97ed 100644 --- a/base/parse.jl +++ b/base/parse.jl @@ -5,7 +5,7 @@ import Base.Checked: add_with_overflow, mul_with_overflow ## string to integer functions ## """ - parse(type, str, [base]) + parse(type, str; base) Parse a string as a number. For `Integer` types, a base can be specified (the default is 10). For floating-point types, the string is parsed as a decimal @@ -18,10 +18,10 @@ If the string does not contain a valid number, an error is raised. julia> parse(Int, "1234") 1234 -julia> parse(Int, "1234", 5) +julia> parse(Int, "1234", base = 5) 194 -julia> parse(Int, "afc", 16) +julia> parse(Int, "afc", base = 16) 2812 julia> parse(Float64, "1.2e-3") @@ -31,9 +31,9 @@ julia> parse(Complex{Float64}, "3.2e-1 + 4.5im") 0.32 + 4.5im ``` """ -parse(T::Type, str, base=Int) +parse(T::Type, str; base = Int) -function parse(::Type{T}, c::Char, base::Integer=36) where T<:Integer +function parse(::Type{T}, c::Char; base::Integer = 36) where T<:Integer a::Int = (base <= 36 ? 10 : 36) 2 <= base <= 62 || throw(ArgumentError("invalid base: base must be 2 ≤ base ≤ 62, got $base")) d = '0' <= c <= '9' ? c-'0' : @@ -202,22 +202,18 @@ end end """ - tryparse(type, str, [base]) + tryparse(type, str; base) Like [`parse`](@ref), but returns either a value of the requested type, or [`nothing`](@ref) if the string does not contain a valid number. """ -tryparse(::Type{T}, s::AbstractString, base::Integer) where {T<:Integer} = - tryparse_internal(T, s, start(s), endof(s), check_valid_base(base), false) -tryparse(::Type{T}, s::AbstractString) where {T<:Integer} = - tryparse_internal(T, s, start(s), endof(s), 0, false) - -function parse(::Type{T}, s::AbstractString, base::Integer) where T<:Integer - tryparse_internal(T, s, start(s), endof(s), check_valid_base(base), true) +function tryparse(::Type{T}, s::AbstractString; base::Union{Nothing,Integer} = nothing) where {T<:Integer} + # Zero base means, "figure it out" + tryparse_internal(T, s, start(s), endof(s), base===nothing ? 0 : check_valid_base(base), false) end -function parse(::Type{T}, s::AbstractString) where T<:Integer - tryparse_internal(T, s, start(s), endof(s), 0, true) # Zero means, "figure it out" +function parse(::Type{T}, s::AbstractString; base::Union{Nothing,Integer} = nothing) where {T<:Integer} + tryparse_internal(T, s, start(s), endof(s), base===nothing ? 0 : check_valid_base(base), true) end ## string to float functions ## diff --git a/base/pcre.jl b/base/pcre.jl index d45252b3d5c5e..4938ffda38c1c 100644 --- a/base/pcre.jl +++ b/base/pcre.jl @@ -88,7 +88,7 @@ function get_ovec(match_data) (Ptr{Cvoid},), match_data) n = ccall((:pcre2_get_ovector_count_8, PCRE_LIB), UInt32, (Ptr{Cvoid},), match_data) - unsafe_wrap(Array, ptr, 2n, false) + unsafe_wrap(Array, ptr, 2n, own = false) end function compile(pattern::AbstractString, options::Integer) diff --git a/base/pointer.jl b/base/pointer.jl index 2ed621c569d94..b0ded31b87a27 100644 --- a/base/pointer.jl +++ b/base/pointer.jl @@ -68,7 +68,7 @@ unsafe_convert(::Type{Ptr{T}}, a::AbstractArray{T}) where {T} = error("conversio # unsafe pointer to array conversions """ - unsafe_wrap(Array, pointer::Ptr{T}, dims, own=false) + unsafe_wrap(Array, pointer::Ptr{T}, dims; own = false) Wrap a Julia `Array` object around the data at the address given by `pointer`, without making a copy. The pointer element type `T` determines the array @@ -80,17 +80,17 @@ This function is labeled "unsafe" because it will crash if `pointer` is not a valid memory address to data of the requested length. """ function unsafe_wrap(::Union{Type{Array},Type{Array{T}},Type{Array{T,N}}}, - p::Ptr{T}, dims::NTuple{N,Int}, own::Bool=false) where {T,N} + p::Ptr{T}, dims::NTuple{N,Int}; own::Bool = false) where {T,N} ccall(:jl_ptr_to_array, Array{T,N}, (Any, Ptr{Cvoid}, Any, Int32), Array{T,N}, p, dims, own) end function unsafe_wrap(::Union{Type{Array},Type{Array{T}},Type{Array{T,1}}}, - p::Ptr{T}, d::Integer, own::Bool=false) where {T} + p::Ptr{T}, d::Integer; own::Bool = false) where {T} ccall(:jl_ptr_to_array_1d, Array{T,1}, (Any, Ptr{Cvoid}, Csize_t, Cint), Array{T,1}, p, d, own) end -unsafe_wrap(Atype::Type, p::Ptr, dims::NTuple{N,<:Integer}, own::Bool=false) where {N} = - unsafe_wrap(Atype, p, convert(Tuple{Vararg{Int}}, dims), own) +unsafe_wrap(Atype::Type, p::Ptr, dims::NTuple{N,<:Integer}; own::Bool = false) where {N} = + unsafe_wrap(Atype, p, convert(Tuple{Vararg{Int}}, dims), own = own) """ unsafe_load(p::Ptr{T}, i::Integer=1) diff --git a/base/precompile.jl b/base/precompile.jl index 8bb4263961909..0a1707eb8075b 100644 --- a/base/precompile.jl +++ b/base/precompile.jl @@ -796,7 +796,7 @@ precompile(Tuple{typeof(Base.setup_stdio), Base.Pipe, Bool}) precompile(Tuple{typeof(Base.setup_stdio), Base.IOStream, Bool}) precompile(Tuple{Type{Base.Process}, Base.Cmd, Ptr{Cvoid}, Base.DevNullStream, Base.Pipe, Base.IOStream}) precompile(Tuple{typeof(Base._jl_spawn), String, Array{String, 1}, Ptr{Cvoid}, Base.Process, Base.DevNullStream, Base.PipeEndpoint, Base.Filesystem.File}) -precompile(Tuple{Type{Base.Timer}, Int64, Float64}) +precompile(Tuple{Type{Base.Timer}, Int64}) precompile(Tuple{typeof(Base.sleep), Int64}) precompile(Tuple{typeof(Base._uv_hook_close), Base.PipeEndpoint}) precompile(Tuple{typeof(Base.eltype), Type{Base.Union{IO, Nothing}}}) diff --git a/base/reflection.jl b/base/reflection.jl index 85d42d1e39905..041e1e5f096bf 100644 --- a/base/reflection.jl +++ b/base/reflection.jl @@ -68,7 +68,7 @@ function fullname(m::Module) end """ - names(x::Module, all::Bool=false, imported::Bool=false) + names(x::Module; all::Bool = false, imported::Bool = false) Get an array of the names exported by a `Module`, excluding deprecated names. If `all` is true, then the list also includes non-exported names defined in the module, @@ -79,7 +79,8 @@ are also included. As a special case, all names defined in `Main` are considered \"exported\", since it is not idiomatic to explicitly export names from `Main`. """ -names(m::Module, all::Bool=false, imported::Bool=false) = sort!(ccall(:jl_module_names, Array{Symbol,1}, (Any, Cint, Cint), m, all, imported)) +names(m::Module; all::Bool = false, imported::Bool = false) = + sort!(ccall(:jl_module_names, Array{Symbol,1}, (Any, Cint, Cint), m, all, imported)) isexported(m::Module, s::Symbol) = ccall(:jl_module_exports_p, Cint, (Any, Any), m, s) != 0 isdeprecated(m::Module, s::Symbol) = ccall(:jl_is_binding_deprecated, Cint, (Any, Any), m, s) != 0 @@ -591,7 +592,7 @@ function _subtypes(m::Module, x::Union{DataType,UnionAll}, return sts end xt = xt::DataType - for s in names(m, true) + for s in names(m, all = true) if isdefined(m, s) && !isdeprecated(m, s) t = getfield(m, s) if isa(t, DataType) @@ -918,15 +919,15 @@ code_llvm(@nospecialize(f), @nospecialize(types=Tuple)) = code_llvm(STDOUT, f, t code_llvm_raw(@nospecialize(f), @nospecialize(types=Tuple)) = code_llvm(STDOUT, f, types, false) """ - code_native([io=STDOUT,], f, types, syntax=:att) + code_native([io=STDOUT,], f, types; syntax = :att) Prints the native assembly instructions generated for running the method matching the given generic function and type signature to `io`. Switch assembly syntax using `syntax` symbol parameter set to `:att` for AT&T syntax or `:intel` for Intel syntax. """ -code_native(io::IO, @nospecialize(f), @nospecialize(types=Tuple), syntax::Symbol=:att) = +code_native(io::IO, @nospecialize(f), @nospecialize(types=Tuple); syntax::Symbol = :att) = print(io, _dump_function(f, types, true, false, false, false, syntax)) -code_native(@nospecialize(f), @nospecialize(types=Tuple), syntax::Symbol=:att) = code_native(STDOUT, f, types, syntax) +code_native(@nospecialize(f), @nospecialize(types=Tuple); syntax::Symbol = :att) = code_native(STDOUT, f, types, syntax = syntax) code_native(::IO, ::Any, ::Symbol) = error("illegal code_native call") # resolve ambiguous call # give a decent error message if we try to instantiate a staged function on non-leaf types @@ -1082,7 +1083,7 @@ function parentmodule(@nospecialize(f), @nospecialize(types)) end """ - hasmethod(f, Tuple type, world=typemax(UInt)) -> Bool + hasmethod(f, Tuple type; world = typemax(UInt)) -> Bool Determine whether the given generic function has a method matching the given `Tuple` of argument types with the upper bound of world age given by `world`. @@ -1093,7 +1094,7 @@ julia> hasmethod(length, Tuple{Array}) true ``` """ -function hasmethod(@nospecialize(f), @nospecialize(t), world=typemax(UInt)) +function hasmethod(@nospecialize(f), @nospecialize(t); world = typemax(UInt)) t = to_tuple_type(t) t = signature_type(f, t) return ccall(:jl_method_exists, Cint, (Any, Any, UInt), typeof(f).name.mt, t, world) != 0 diff --git a/base/regex.jl b/base/regex.jl index 716f5a379001e..06b3768159708 100644 --- a/base/regex.jl +++ b/base/regex.jl @@ -206,7 +206,7 @@ match(r::Regex, s::AbstractString, i::Integer) = throw(ArgumentError( )) """ - matchall(r::Regex, s::AbstractString[, overlap::Bool=false]) -> Vector{AbstractString} + matchall(r::Regex, s::AbstractString; overlap::Bool = false]) -> Vector{AbstractString} Return a vector of the matching substrings from [`eachmatch`](@ref). @@ -221,14 +221,14 @@ julia> matchall(rx, "a1a2a3a") "a1a" "a3a" -julia> matchall(rx, "a1a2a3a", true) +julia> matchall(rx, "a1a2a3a", overlap = true) 3-element Array{SubString{String},1}: "a1a" "a2a" "a3a" ``` """ -function matchall(re::Regex, str::String, overlap::Bool=false) +function matchall(re::Regex, str::String; overlap::Bool = false) regex = compile(re).regex n = sizeof(str) matches = SubString{String}[] @@ -262,8 +262,8 @@ function matchall(re::Regex, str::String, overlap::Bool=false) matches end -matchall(re::Regex, str::SubString, overlap::Bool=false) = - matchall(re, String(str), overlap) +matchall(re::Regex, str::SubString; overlap::Bool = false) = + matchall(re, String(str), overlap = overlap) # TODO: return only start index and update deprecation function findnext(re::Regex, str::Union{String,SubString}, idx::Integer) @@ -416,12 +416,8 @@ function next(itr::RegexMatchIterator, prev_match) (prev_match, nothing) end -function eachmatch(re::Regex, str::AbstractString, ovr::Bool) - RegexMatchIterator(re,str,ovr) -end - """ - eachmatch(r::Regex, s::AbstractString[, overlap::Bool=false]) + eachmatch(r::Regex, s::AbstractString; overlap::Bool=false]) Search for all matches of a the regular expression `r` in `s` and return a iterator over the matches. If overlap is `true`, the matching sequences are allowed to overlap indices in the @@ -440,14 +436,15 @@ julia> collect(m) RegexMatch("a1a") RegexMatch("a3a") -julia> collect(eachmatch(rx, "a1a2a3a", true)) +julia> collect(eachmatch(rx, "a1a2a3a", overlap = true)) 3-element Array{RegexMatch,1}: RegexMatch("a1a") RegexMatch("a2a") RegexMatch("a3a") ``` """ -eachmatch(re::Regex, str::AbstractString) = RegexMatchIterator(re,str) +eachmatch(re::Regex, str::AbstractString; overlap = false) = + RegexMatchIterator(re, str, overlap) ## comparison ## diff --git a/base/show.jl b/base/show.jl index 4ba28a7bbb5c7..eea3869d2d400 100644 --- a/base/show.jl +++ b/base/show.jl @@ -1725,7 +1725,7 @@ directsubtype(a::Union, b::DataType) = directsubtype(a.a, b) || directsubtype(a. # Fallback to handle TypeVar's directsubtype(a, b::DataType) = false function dumpsubtypes(io::IO, x::DataType, m::Module, n::Int, indent) - for s in names(m, true) + for s in names(m, all = true) if isdefined(m, s) && !isdeprecated(m, s) t = getfield(m, s) if t === x || t === m diff --git a/base/socket.jl b/base/socket.jl index 127966e4c0036..46e423470353c 100644 --- a/base/socket.jl +++ b/base/socket.jl @@ -174,7 +174,7 @@ function parse(::Type{IPv4}, str::AbstractString) if length(f) > 1 && f[1] == '0' throw(ArgumentError(ipv4_leading_zero_error)) else - r = parse(Int,f,10) + r = parse(Int, f, base = 10) end if i != length(fields) if r < 0 || r > 255 @@ -207,7 +207,7 @@ function parseipv6fields(fields,num_fields) cf -= 1 continue end - ret |= UInt128(parse(Int,f,16))<<(cf*16) + ret |= UInt128(parse(Int, f, base = 16))<<(cf*16) cf -= 1 end ret @@ -542,7 +542,7 @@ function uv_recvcb(handle::Ptr{Cvoid}, nread::Cssize_t, buf::Ptr{Cvoid}, addr::P ccall(:jl_sockaddr_host6, UInt32, (Ptr{Cvoid}, Ptr{UInt8}), addr, pointer(tmp)) IPv6(ntoh(tmp[1])) end - buf = unsafe_wrap(Array, convert(Ptr{UInt8}, buf_addr), Int(nread), true) + buf = unsafe_wrap(Array, convert(Ptr{UInt8}, buf_addr), Int(nread), own = true) notify(sock.recvnotify, (addrout, buf)) end ccall(:uv_udp_recv_stop, Cint, (Ptr{Cvoid},), sock.handle) diff --git a/base/stream.jl b/base/stream.jl index efb5e927045c3..778ba47bda452 100644 --- a/base/stream.jl +++ b/base/stream.jl @@ -773,7 +773,7 @@ function readbytes!(s::LibuvStream, a::Vector{UInt8}, nb::Int) else try stop_reading(s) # Just playing it safe, since we are going to switch buffers. - newbuf = PipeBuffer(a, #=maxsize=# nb) + newbuf = PipeBuffer(a, maxsize = nb) newbuf.size = 0 # reset the write pointer to the beginning s.buffer = newbuf write(newbuf, sbuf) @@ -810,7 +810,7 @@ function unsafe_read(s::LibuvStream, p::Ptr{UInt8}, nb::UInt) else try stop_reading(s) # Just playing it safe, since we are going to switch buffers. - newbuf = PipeBuffer(unsafe_wrap(Array, p, nb), #=maxsize=# Int(nb)) + newbuf = PipeBuffer(unsafe_wrap(Array, p, nb), maxsize = Int(nb)) newbuf.size = 0 # reset the write pointer to the beginning s.buffer = newbuf write(newbuf, sbuf) diff --git a/base/strings/util.jl b/base/strings/util.jl index e477bfd42788a..91afc96de9997 100644 --- a/base/strings/util.jl +++ b/base/strings/util.jl @@ -70,7 +70,7 @@ startswith(a::Vector{UInt8}, b::Vector{UInt8}) = length(a) ≥ length(b) && # TODO: fast endswith """ - chop(s::AbstractString, head::Integer=0, tail::Integer=1) + chop(s::AbstractString; head::Integer = 0, tail::Integer = 1) Remove the first `head` and the last `tail` characters from `s`. The call `chop(s)` removes the last character from `s`. @@ -85,16 +85,19 @@ julia> a = "March" julia> chop(a) "Marc" -julia> chop(a, 1, 2) +julia> chop(a, head = 1, tail = 2) "ar" -julia> chop(a, 5, 5) +julia> chop(a, head = 5, tail = 5) "" ``` """ -chop(s::AbstractString) = SubString(s, start(s), prevind(s, endof(s))) -chop(s::AbstractString, head::Integer, tail::Integer) = +function chop(s::AbstractString; head::Integer = 0, tail::Integer = 1) SubString(s, nextind(s, start(s), head), prevind(s, endof(s), tail)) +end + +# TODO: optimization for the default case based on +# chop(s::AbstractString) = SubString(s, start(s), prevind(s, endof(s))) """ chomp(s::AbstractString) diff --git a/base/summarysize.jl b/base/summarysize.jl index ca516b1a6ac9a..185b43b851ff2 100644 --- a/base/summarysize.jl +++ b/base/summarysize.jl @@ -130,7 +130,7 @@ end function (ss::SummarySize)(obj::Module) haskey(ss.seen, obj) ? (return 0) : (ss.seen[obj] = true) size::Int = Core.sizeof(obj) - for binding in names(obj, true) + for binding in names(obj, all = true) if isdefined(obj, binding) && !isdeprecated(obj, binding) value = getfield(obj, binding) if !isa(value, Module) || parentmodule(value) === obj diff --git a/base/task.jl b/base/task.jl index bf02c44f9343f..41da005e17526 100644 --- a/base/task.jl +++ b/base/task.jl @@ -357,7 +357,7 @@ function timedwait(testcb::Function, secs::Float64; pollint::Float64=0.1) end if !testcb() - t = Timer(timercb, pollint, pollint) + t = Timer(timercb, pollint, interval = pollint) ret = fetch(done) close(t) else diff --git a/doc/src/base/base.md b/doc/src/base/base.md index e92cb39e08841..32d3c51589f44 100644 --- a/doc/src/base/base.md +++ b/doc/src/base/base.md @@ -323,7 +323,7 @@ Base.ExponentialBackOff ## Events ```@docs -Base.Timer(::Function, ::Real, ::Real) +Base.Timer(::Function, ::Real) Base.Timer Base.AsyncCondition Base.AsyncCondition(::Function) diff --git a/doc/src/base/numbers.md b/doc/src/base/numbers.md index 4be2570374488..033590a69c0f6 100644 --- a/doc/src/base/numbers.md +++ b/doc/src/base/numbers.md @@ -49,7 +49,7 @@ Base.base Base.digits Base.digits! Base.bitstring -Base.parse(::Type, ::Any, ::Any) +Base.parse Base.tryparse Base.big Base.signed diff --git a/doc/src/devdocs/reflection.md b/doc/src/devdocs/reflection.md index a7147f5d80736..d664ef0aeb92d 100644 --- a/doc/src/devdocs/reflection.md +++ b/doc/src/devdocs/reflection.md @@ -5,7 +5,7 @@ Julia provides a variety of runtime reflection capabilities. ## Module bindings The exported names for a `Module` are available using [`names(m::Module)`](@ref), which will return -an array of [`Symbol`](@ref) elements representing the exported bindings. `names(m::Module, true)` +an array of [`Symbol`](@ref) elements representing the exported bindings. `names(m::Module, all = true)` returns symbols for all bindings in `m`, regardless of export status. ## DataType fields diff --git a/doc/src/manual/calling-c-and-fortran-code.md b/doc/src/manual/calling-c-and-fortran-code.md index e2ec0d8a94c56..2058b46eda783 100644 --- a/doc/src/manual/calling-c-and-fortran-code.md +++ b/doc/src/manual/calling-c-and-fortran-code.md @@ -963,7 +963,7 @@ Currently, this is only supported for primitive types or other pointer-free (`is Any operation that throws an error is probably currently unimplemented and should be posted as a bug so that it can be resolved. -If the pointer of interest is a plain-data array (primitive type or immutable struct), the function [`unsafe_wrap(Array, ptr,dims,[own])`](@ref) +If the pointer of interest is a plain-data array (primitive type or immutable struct), the function [`unsafe_wrap(Array, ptr,dims, own = false)`](@ref) may be more useful. The final parameter should be true if Julia should "take ownership" of the underlying buffer and call `free(ptr)` when the returned `Array` object is finalized. If the `own` parameter is omitted or false, the caller must ensure the buffer remains in existence until diff --git a/doc/src/manual/functions.md b/doc/src/manual/functions.md index f6ffc69821f35..c4ce2e98b7ae2 100644 --- a/doc/src/manual/functions.md +++ b/doc/src/manual/functions.md @@ -447,12 +447,12 @@ call will fail, just as it would if too many arguments were given explicitly. ## Optional Arguments In many cases, function arguments have sensible default values and therefore might not need to -be passed explicitly in every call. For example, the library function [`parse(T, num, base)`](@ref) +be passed explicitly in every call. For example, the library function [`parse(T, num, base = base)`](@ref) interprets a string as a number in some base. The `base` argument defaults to `10`. This behavior can be expressed concisely as: ```julia -function parse(T, num, base=10) +function parse(T, num; base = 10) ### end ``` @@ -461,13 +461,13 @@ With this definition, the function can be called with either two or three argume is automatically passed when a third argument is not specified: ```jldoctest -julia> parse(Int,"12",10) +julia> parse(Int, "12", base = 10) 12 -julia> parse(Int,"12",3) +julia> parse(Int, "12", base = 3) 5 -julia> parse(Int,"12") +julia> parse(Int, "12") 12 ``` diff --git a/examples/typetree.jl b/examples/typetree.jl index f06c30b70e3ad..76736a2007ed2 100644 --- a/examples/typetree.jl +++ b/examples/typetree.jl @@ -74,7 +74,7 @@ end # examine all symbols in module and store those that are types function store_all_from(m::Module) - for s in names(m, true) + for s in names(m, all = true) if isdefined(m, s) && !Base.isdeprecated(m, s) t = getfield(m, s) if isa(t, Type) && t !== Union{} diff --git a/stdlib/Dates/src/types.jl b/stdlib/Dates/src/types.jl index bb856d790baf0..133225a300dcd 100644 --- a/stdlib/Dates/src/types.jl +++ b/stdlib/Dates/src/types.jl @@ -353,7 +353,8 @@ end import Base: sleep, Timer, timedwait sleep(time::Period) = sleep(toms(time) / 1000) -Timer(time::Period, repeat::Period=Second(0)) = Timer(toms(time) / 1000, toms(repeat) / 1000) +Timer(time::Period; interval::Period = Second(0)) = + Timer(toms(time) / 1000, interval = toms(interval) / 1000) timedwait(testcb::Function, time::Period) = timedwait(testcb, toms(time) / 1000) Base.OrderStyle(::Type{<:AbstractTime}) = Base.Ordered() diff --git a/stdlib/FileWatching/test/runtests.jl b/stdlib/FileWatching/test/runtests.jl index 8aef7119e2c71..560d66161e00c 100644 --- a/stdlib/FileWatching/test/runtests.jl +++ b/stdlib/FileWatching/test/runtests.jl @@ -125,14 +125,14 @@ end # issue #12473 # make sure 1-shot timers work let a = [] - Timer(t -> push!(a, 1), 0.01, 0) + Timer(t -> push!(a, 1), 0.01, interval = 0) sleep(0.2) @test a == [1] end # make sure repeating timers work @noinline function make_unrooted_timer(a) - t = Timer(0.0, 0.1) + t = Timer(0.0, interval = 0.1) finalizer(t -> a[] += 1, t) wait(t) e = @elapsed for i = 1:5 diff --git a/stdlib/REPL/src/REPLCompletions.jl b/stdlib/REPL/src/REPLCompletions.jl index 82cdfefbb991e..8ef4ade2ddf33 100644 --- a/stdlib/REPL/src/REPLCompletions.jl +++ b/stdlib/REPL/src/REPLCompletions.jl @@ -21,8 +21,8 @@ function appendmacro!(syms, macros, needle, endchar) end end -function filtered_mod_names(ffunc::Function, mod::Module, name::AbstractString, all::Bool=false, imported::Bool=false) - ssyms = names(mod, all, imported) +function filtered_mod_names(ffunc::Function, mod::Module, name::AbstractString, all::Bool = false, imported::Bool = false) + ssyms = names(mod, all = all, imported = imported) filter!(ffunc, ssyms) syms = String[string(s) for s in ssyms] macros = filter(x -> startswith(x, "@" * name), syms) diff --git a/stdlib/REPL/src/emoji_symbols.jl b/stdlib/REPL/src/emoji_symbols.jl index f8a5043f19f36..40f943cf246dd 100644 --- a/stdlib/REPL/src/emoji_symbols.jl +++ b/stdlib/REPL/src/emoji_symbols.jl @@ -11,7 +11,7 @@ for emj in emojis if '-' in unicode continue end - result[name] = "$(Char(parse(UInt32, unicode, 16)))" + result[name] = "$(Char(parse(UInt32, unicode, base = 16)))" end skeys = sort(collect(keys(result))) diff --git a/stdlib/REPL/src/latex_symbols.jl b/stdlib/REPL/src/latex_symbols.jl index b9b00b6bbb118..8f9c1ef8d5399 100644 --- a/stdlib/REPL/src/latex_symbols.jl +++ b/stdlib/REPL/src/latex_symbols.jl @@ -23,7 +23,7 @@ for c in child_nodes(root(xdoc)) if latex !== nothing L = strip(content(latex)) id = attribute(ce, "id") - U = string(map(s -> Char(parse(Int, s, 16)), + U = string(map(s -> Char(parse(Int, s, base = 16)), split(id[2:end], "-"))...) if contains(L, r"^\\[A-Za-z]+$") && !isa(U,String) if L in Ls @@ -55,7 +55,7 @@ open(fname) do f for L in eachline(f) x = map(s -> rstrip(s, [' ','\t','\n']), split(replace(L, r"[{}\"]+" => "\t"), "\t")) - c = Char(parse(Int, x[2], 16)) + c = Char(parse(Int, x[2], base = 16)) if (Base.is_id_char(c) || Base.isoperator(Symbol(c))) && string(c) ∉ latex_strings && !isascii(c) tabcomname = escape_string(x[3]) diff --git a/stdlib/Random/src/DSFMT.jl b/stdlib/Random/src/DSFMT.jl index e0a4d3d22328d..58e5ed23bb2ab 100644 --- a/stdlib/Random/src/DSFMT.jl +++ b/stdlib/Random/src/DSFMT.jl @@ -105,7 +105,7 @@ struct GF2X z::BigInt end -GF2X(s::AbstractString) = GF2X(parse(BigInt, reverse(s), 16)) +GF2X(s::AbstractString) = GF2X(parse(BigInt, reverse(s), base = 16)) Base.string(f::GF2X) = reverse(base(16, f.z)) Base.:(==)(f::GF2X, g::GF2X) = f.z == g.z Base.copy(f::GF2X) = GF2X(MPZ.set(f.z)) diff --git a/stdlib/Random/src/RNGs.jl b/stdlib/Random/src/RNGs.jl index 55c629a5b73d1..234b9b45c49ce 100644 --- a/stdlib/Random/src/RNGs.jl +++ b/stdlib/Random/src/RNGs.jl @@ -246,7 +246,7 @@ function make_seed() try seed = hash(seed, parse(UInt64, read(pipeline(`ifconfig`, `sha1sum`), String)[1:40], - 16)) + base = 16)) end return make_seed(seed) end diff --git a/stdlib/Serialization/src/Serialization.jl b/stdlib/Serialization/src/Serialization.jl index b6afb86bf0537..ae1368d71da32 100644 --- a/stdlib/Serialization/src/Serialization.jl +++ b/stdlib/Serialization/src/Serialization.jl @@ -1193,7 +1193,7 @@ end deserialize(s::AbstractSerializer, ::Type{BigFloat}) = parse(BigFloat, deserialize(s)) -deserialize(s::AbstractSerializer, ::Type{BigInt}) = parse(BigInt, deserialize(s), 62) +deserialize(s::AbstractSerializer, ::Type{BigInt}) = parse(BigInt, deserialize(s), base = 62) function deserialize(s::AbstractSerializer, t::Type{Regex}) pattern = deserialize(s) diff --git a/stdlib/SparseArrays/docs/src/index.md b/stdlib/SparseArrays/docs/src/index.md index b0c7f34d409e7..d55c7f07cbdb9 100644 --- a/stdlib/SparseArrays/docs/src/index.md +++ b/stdlib/SparseArrays/docs/src/index.md @@ -213,10 +213,8 @@ SparseArrays.sprandn SparseArrays.nonzeros SparseArrays.rowvals SparseArrays.nzrange -SparseArrays.dropzeros!(::SparseMatrixCSC, ::Bool) -SparseArrays.dropzeros(::SparseMatrixCSC, ::Bool) -SparseArrays.dropzeros!(::SparseVector, ::Bool) -SparseArrays.dropzeros(::SparseVector, ::Bool) +SparseArrays.dropzeros! +SparseArrays.dropzeros SparseArrays.permute permute!{Tv, Ti, Tp <: Integer, Tq <: Integer}(::SparseMatrixCSC{Tv,Ti}, ::SparseMatrixCSC{Tv,Ti}, ::AbstractArray{Tp,1}, ::AbstractArray{Tq,1}) ``` diff --git a/stdlib/SparseArrays/src/deprecated.jl b/stdlib/SparseArrays/src/deprecated.jl index 87be3f449529c..76f9f461a9b1e 100644 --- a/stdlib/SparseArrays/src/deprecated.jl +++ b/stdlib/SparseArrays/src/deprecated.jl @@ -222,6 +222,11 @@ end import Base: asyncmap @deprecate asyncmap(f, s::AbstractSparseArray...; kwargs...) sparse(asyncmap(f, map(Array, s)...; kwargs...)) +#25395 keywords unlocked +@deprecate dropzeros(x, trim) dropzeros(x, trim = trim) +@deprecate dropzeros!(x, trim) dropzeros!(x, trim = trim) +@deprecate droptol!(A, tol, trim) droptol!(A, tol, trim = trim) + # END 0.7 deprecations # BEGIN 1.0 deprecations diff --git a/stdlib/SparseArrays/src/sparsematrix.jl b/stdlib/SparseArrays/src/sparsematrix.jl index 81b2e73758090..f710fa9afe501 100644 --- a/stdlib/SparseArrays/src/sparsematrix.jl +++ b/stdlib/SparseArrays/src/sparsematrix.jl @@ -1224,11 +1224,11 @@ function triu!(A::SparseMatrixCSC, k::Integer = 0, trim::Bool = true) fkeep!(A, (i, j, x) -> j >= i + k, trim) end -droptol!(A::SparseMatrixCSC, tol, trim::Bool = true) = +droptol!(A::SparseMatrixCSC, tol; trim::Bool = true) = fkeep!(A, (i, j, x) -> abs(x) > tol, trim) """ - dropzeros!(A::SparseMatrixCSC, trim::Bool = true) + dropzeros!(A::SparseMatrixCSC; trim::Bool = true) Removes stored numerical zeros from `A`, optionally trimming resulting excess space from `A.rowval` and `A.nzval` when `trim` is `true`. @@ -1236,9 +1236,9 @@ Removes stored numerical zeros from `A`, optionally trimming resulting excess sp For an out-of-place version, see [`dropzeros`](@ref). For algorithmic information, see `fkeep!`. """ -dropzeros!(A::SparseMatrixCSC, trim::Bool = true) = fkeep!(A, (i, j, x) -> x != 0, trim) +dropzeros!(A::SparseMatrixCSC; trim::Bool = true) = fkeep!(A, (i, j, x) -> x != 0, trim) """ - dropzeros(A::SparseMatrixCSC, trim::Bool = true) + dropzeros(A::SparseMatrixCSC; trim::Bool = true) Generates a copy of `A` and removes stored numerical zeros from that copy, optionally trimming excess space from the result's `rowval` and `nzval` arrays when `trim` is `true`. @@ -1259,7 +1259,7 @@ julia> dropzeros(A) [3, 3] = 1.0 ``` """ -dropzeros(A::SparseMatrixCSC, trim::Bool = true) = dropzeros!(copy(A), trim) +dropzeros(A::SparseMatrixCSC; trim::Bool = true) = dropzeros!(copy(A), trim = trim) ## Find methods diff --git a/stdlib/SparseArrays/src/sparsevector.jl b/stdlib/SparseArrays/src/sparsevector.jl index e29b60de1419d..84cfb1844ccfc 100644 --- a/stdlib/SparseArrays/src/sparsevector.jl +++ b/stdlib/SparseArrays/src/sparsevector.jl @@ -1972,10 +1972,10 @@ function fkeep!(x::SparseVector, f, trim::Bool = true) x end -droptol!(x::SparseVector, tol, trim::Bool = true) = fkeep!(x, (i, x) -> abs(x) > tol, trim) +droptol!(x::SparseVector, tol; trim::Bool = true) = fkeep!(x, (i, x) -> abs(x) > tol, trim) """ - dropzeros!(x::SparseVector, trim::Bool = true) + dropzeros!(x::SparseVector; trim::Bool = true) Removes stored numerical zeros from `x`, optionally trimming resulting excess space from `x.nzind` and `x.nzval` when `trim` is `true`. @@ -1983,9 +1983,10 @@ Removes stored numerical zeros from `x`, optionally trimming resulting excess sp For an out-of-place version, see [`dropzeros`](@ref). For algorithmic information, see `fkeep!`. """ -dropzeros!(x::SparseVector, trim::Bool = true) = fkeep!(x, (i, x) -> x != 0, trim) +dropzeros!(x::SparseVector; trim::Bool = true) = fkeep!(x, (i, x) -> x != 0, trim) + """ - dropzeros(x::SparseVector, trim::Bool = true) + dropzeros(x::SparseVector; trim::Bool = true) Generates a copy of `x` and removes numerical zeros from that copy, optionally trimming excess space from the result's `nzind` and `nzval` arrays when `trim` is `true`. @@ -2006,7 +2007,7 @@ julia> dropzeros(A) [3] = 1.0 ``` """ -dropzeros(x::SparseVector, trim::Bool = true) = dropzeros!(copy(x), trim) +dropzeros(x::SparseVector; trim::Bool = true) = dropzeros!(copy(x), trim = trim) function _fillnonzero!(arr::SparseMatrixCSC{Tv, Ti}, val) where {Tv,Ti} diff --git a/stdlib/SparseArrays/test/sparse.jl b/stdlib/SparseArrays/test/sparse.jl index e9fed185f64a4..3bf048920dba5 100644 --- a/stdlib/SparseArrays/test/sparse.jl +++ b/stdlib/SparseArrays/test/sparse.jl @@ -1417,15 +1417,15 @@ end for Awithzeros in (Aposzeros, Anegzeros, Abothsigns) # Basic functionality / dropzeros! @test dropzeros!(copy(Awithzeros)) == A - @test dropzeros!(copy(Awithzeros), false) == A + @test dropzeros!(copy(Awithzeros), trim = false) == A # Basic functionality / dropzeros @test dropzeros(Awithzeros) == A - @test dropzeros(Awithzeros, false) == A + @test dropzeros(Awithzeros, trim = false) == A # Check trimming works as expected @test length(dropzeros!(copy(Awithzeros)).nzval) == length(A.nzval) @test length(dropzeros!(copy(Awithzeros)).rowval) == length(A.rowval) - @test length(dropzeros!(copy(Awithzeros), false).nzval) == length(Awithzeros.nzval) - @test length(dropzeros!(copy(Awithzeros), false).rowval) == length(Awithzeros.rowval) + @test length(dropzeros!(copy(Awithzeros), trim = false).nzval) == length(Awithzeros.nzval) + @test length(dropzeros!(copy(Awithzeros), trim = false).rowval) == length(Awithzeros.rowval) end end # original lone dropzeros test diff --git a/stdlib/SparseArrays/test/sparsevector.jl b/stdlib/SparseArrays/test/sparsevector.jl index 5d8cb9b8e377c..46cf1105cb31f 100644 --- a/stdlib/SparseArrays/test/sparsevector.jl +++ b/stdlib/SparseArrays/test/sparsevector.jl @@ -1050,15 +1050,15 @@ end for vwithzeros in (vposzeros, vnegzeros, vbothsigns) # Basic functionality / dropzeros! @test dropzeros!(copy(vwithzeros)) == v - @test dropzeros!(copy(vwithzeros), false) == v + @test dropzeros!(copy(vwithzeros), trim = false) == v # Basic functionality / dropzeros @test dropzeros(vwithzeros) == v - @test dropzeros(vwithzeros, false) == v + @test dropzeros(vwithzeros, trim = false) == v # Check trimming works as expected @test length(dropzeros!(copy(vwithzeros)).nzval) == length(v.nzval) @test length(dropzeros!(copy(vwithzeros)).nzind) == length(v.nzind) - @test length(dropzeros!(copy(vwithzeros), false).nzval) == length(vwithzeros.nzval) - @test length(dropzeros!(copy(vwithzeros), false).nzind) == length(vwithzeros.nzind) + @test length(dropzeros!(copy(vwithzeros), trim = false).nzval) == length(vwithzeros.nzval) + @test length(dropzeros!(copy(vwithzeros), trim = false).nzind) == length(vwithzeros.nzind) end end # original dropzeros! test diff --git a/stdlib/SuiteSparse/src/cholmod.jl b/stdlib/SuiteSparse/src/cholmod.jl index b376d606585f0..8ba42d1d0c7d8 100644 --- a/stdlib/SuiteSparse/src/cholmod.jl +++ b/stdlib/SuiteSparse/src/cholmod.jl @@ -816,7 +816,7 @@ end function get_perm(F::Factor) s = unsafe_load(pointer(F)) - p = unsafe_wrap(Array, s.Perm, s.n, false) + p = unsafe_wrap(Array, s.Perm, s.n, own = false) p .+ 1 end get_perm(FC::FactorComponent) = get_perm(Factor(FC)) @@ -1074,9 +1074,9 @@ function SparseMatrixCSC{Tv,SuiteSparse_long}(A::Sparse{Tv}) where Tv end B = SparseMatrixCSC(s.nrow, s.ncol, - increment(unsafe_wrap(Array, s.p, (s.ncol + 1,), false)), - increment(unsafe_wrap(Array, s.i, (s.nzmax,), false)), - copy(unsafe_wrap(Array, s.x, (s.nzmax,), false))) + increment(unsafe_wrap(Array, s.p, (s.ncol + 1,), own = false)), + increment(unsafe_wrap(Array, s.i, (s.nzmax,), own = false)), + copy(unsafe_wrap(Array, s.x, (s.nzmax,), own = false))) if s.sorted == 0 return SparseArrays.sortSparseMatrixCSC!(B) @@ -1091,9 +1091,9 @@ function (::Type{Symmetric{Float64,SparseMatrixCSC{Float64,SuiteSparse_long}}})( end B = Symmetric(SparseMatrixCSC(s.nrow, s.ncol, - increment(unsafe_wrap(Array, s.p, (s.ncol + 1,), false)), - increment(unsafe_wrap(Array, s.i, (s.nzmax,), false)), - copy(unsafe_wrap(Array, s.x, (s.nzmax,), false))), s.stype > 0 ? :U : :L) + increment(unsafe_wrap(Array, s.p, (s.ncol + 1,), own = false)), + increment(unsafe_wrap(Array, s.i, (s.nzmax,), own = false)), + copy(unsafe_wrap(Array, s.x, (s.nzmax,), own = false))), s.stype > 0 ? :U : :L) if s.sorted == 0 return SparseArrays.sortSparseMatrixCSC!(B.data) @@ -1108,9 +1108,9 @@ function Hermitian{Tv,SparseMatrixCSC{Tv,SuiteSparse_long}}(A::Sparse{Tv}) where end B = Hermitian(SparseMatrixCSC(s.nrow, s.ncol, - increment(unsafe_wrap(Array, s.p, (s.ncol + 1,), false)), - increment(unsafe_wrap(Array, s.i, (s.nzmax,), false)), - copy(unsafe_wrap(Array, s.x, (s.nzmax,), false))), s.stype > 0 ? :U : :L) + increment(unsafe_wrap(Array, s.p, (s.ncol + 1,), own = false)), + increment(unsafe_wrap(Array, s.i, (s.nzmax,), own = false)), + copy(unsafe_wrap(Array, s.x, (s.nzmax,), own = false))), s.stype > 0 ? :U : :L) if s.sorted == 0 return SparseArrays.sortSparseMatrixCSC!(B.data) @@ -1264,7 +1264,7 @@ function getindex(A::Sparse{T}, i0::Integer, i1::Integer) where T r1 = Int(unsafe_load(s.p, i1) + 1) r2 = Int(unsafe_load(s.p, i1 + 1)) (r1 > r2) && return zero(T) - r1 = Int(searchsortedfirst(unsafe_wrap(Array, s.i, (s.nzmax,), false), + r1 = Int(searchsortedfirst(unsafe_wrap(Array, s.i, (s.nzmax,), own = false), i0 - 1, r1, r2, Base.Order.Forward)) ((r1 > r2) || (unsafe_load(s.i, r1) + 1 != i0)) ? zero(T) : unsafe_load(s.x, r1) end diff --git a/stdlib/Test/src/Test.jl b/stdlib/Test/src/Test.jl index 42c9bcbbfd367..0304317551c13 100644 --- a/stdlib/Test/src/Test.jl +++ b/stdlib/Test/src/Test.jl @@ -1281,7 +1281,7 @@ function detect_ambiguities(mods...; end ambs = Set{Tuple{Method,Method}}() for mod in mods - for n in names(mod, true, imported) + for n in names(mod, all = true, imported = imported) Base.isdeprecated(mod, n) && continue if !isdefined(mod, n) println("Skipping ", mod, '.', n) # typically stale exports @@ -1322,7 +1322,7 @@ function detect_unbound_args(mods...; recursive::Bool = false) ambs = Set{Method}() for mod in mods - for n in names(mod, true, imported) + for n in names(mod, all = true, imported = imported) Base.isdeprecated(mod, n) && continue if !isdefined(mod, n) println("Skipping ", mod, '.', n) # typically stale exports diff --git a/test/asmvariant.jl b/test/asmvariant.jl index 28b0fbd6f124b..999d37eccced4 100644 --- a/test/asmvariant.jl +++ b/test/asmvariant.jl @@ -14,13 +14,13 @@ if Sys.ARCH === :x86_64 || contains(string(Sys.ARCH), ix86) buf = IOBuffer() output="" #test that the string output is at&t syntax by checking for occurrences of '%'s - code_native(buf,linear_foo,(),:att) + code_native(buf,linear_foo,(), syntax = :att) output=String(take!(buf)) @test contains(output,rgx) #test that the code output is intel syntax by checking it has no occurrences of '%' - code_native(buf,linear_foo,(),:intel) + code_native(buf,linear_foo,(), syntax = :intel) output=String(take!(buf)) @test !contains(output,rgx) diff --git a/test/bigint.jl b/test/bigint.jl index f705ff7268d9f..b4886df8220c2 100644 --- a/test/bigint.jl +++ b/test/bigint.jl @@ -313,7 +313,7 @@ end @test Base.ndigits0zpb(big(0), big(rand(2:100))) == 0 # digits with BigInt bases (#16844) -@test digits(big(2)^256, big(2)^128) == [0, 0, 1] +@test digits(big(2)^256, base = big(2)^128) == [0, 0, 1] @testset "conversion from float" begin @test BigInt(2.0) == BigInt(2.0f0) == BigInt(big(2.0)) == 2 diff --git a/test/core.jl b/test/core.jl index a6c52bb51c414..ac686bd68c8e2 100644 --- a/test/core.jl +++ b/test/core.jl @@ -910,8 +910,8 @@ let A = [1] end # Module() constructor -@test names(Module(:anonymous), true, true) == [:anonymous] -@test names(Module(:anonymous, false), true, true) == [:anonymous] +@test names(Module(:anonymous), all = true, imported = true) == [:anonymous] +@test names(Module(:anonymous, false), all = true, imported = true) == [:anonymous] # exception from __init__() let didthrow = @@ -4158,7 +4158,7 @@ ccall(:jl_array_grow_beg, Cvoid, (Any, UInt), d, 8) @test check_nul(d) f = unsafe_wrap(Array, pointer(d), length(d)) @test !check_nul(f) -f = unsafe_wrap(Array, ccall(:malloc, Ptr{UInt8}, (Csize_t,), 10), 10, true) +f = unsafe_wrap(Array, ccall(:malloc, Ptr{UInt8}, (Csize_t,), 10), 10, own = true) @test !check_nul(f) end diff --git a/test/file.jl b/test/file.jl index e9d58c6971ff9..db749d8882e6c 100644 --- a/test/file.jl +++ b/test/file.jl @@ -1026,7 +1026,7 @@ function test_13559() end test_13559() end -@test_throws ArgumentError mkpath("fakepath", -1) +@test_throws ArgumentError mkpath("fakepath", mode = -1) # issue #22566 # issue #24037 (disabling on FreeBSD) diff --git a/test/intfuncs.jl b/test/intfuncs.jl index 82c67f30e745e..f3db1ebc52437 100644 --- a/test/intfuncs.jl +++ b/test/intfuncs.jl @@ -142,14 +142,14 @@ end @test bitstring(Int128(3)) == "00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011" end @testset "digits/base" begin - @test digits(4, 2) == [0, 0, 1] - @test digits(5, 3) == [2, 1] + @test digits(4, base = 2) == [0, 0, 1] + @test digits(5, base = 3) == [2, 1] @testset "digits/base with negative bases" begin - @testset "digits(n::$T, b)" for T in (Int, UInt, BigInt, Int32) - @test digits(T(8163), -10) == [3, 4, 2, 2, 1] + @testset "digits(n::$T, base = b)" for T in (Int, UInt, BigInt, Int32) + @test digits(T(8163), base = -10) == [3, 4, 2, 2, 1] if !(T<:Unsigned) - @test digits(T(-8163), -10) == [7, 7, 9, 9] + @test digits(T(-8163), base = -10) == [7, 7, 9, 9] end end @test [base(b, n) diff --git a/test/misc.jl b/test/misc.jl index 8e4173c8090b3..4d65bc6f18054 100644 --- a/test/misc.jl +++ b/test/misc.jl @@ -159,7 +159,7 @@ end # test that they don't introduce global vars global v11801, t11801, names_before_timing -names_before_timing = names(@__MODULE__, true) +names_before_timing = names(@__MODULE__, all = true) let t = @elapsed 1+1 @test isa(t, Real) && t >= 0 @@ -178,7 +178,7 @@ v11801, t11801 = @timed sin(1) @test v11801 == sin(1) @test isa(t11801,Real) && t11801 >= 0 -@test names(@__MODULE__, true) == names_before_timing +@test names(@__MODULE__, all = true) == names_before_timing # interactive utilities diff --git a/test/numbers.jl b/test/numbers.jl index df0530ee03bb3..101efaa43e987 100644 --- a/test/numbers.jl +++ b/test/numbers.jl @@ -2465,24 +2465,24 @@ ndigf(n) = Float64(log(Float32(n))) @test sum([Int128(1) Int128(2)]) == Int128(3) @testset "digits and digits!" begin - @test digits(24, 2) == [0, 0, 0, 1, 1] - @test digits(24, 2, 3) == [0, 0, 0, 1, 1] - @test digits(24, 2, 7) == [0, 0, 0, 1, 1, 0, 0] + @test digits(24, base = 2) == [0, 0, 0, 1, 1] + @test digits(24, base = 2, pad = 3) == [0, 0, 0, 1, 1] + @test digits(24, base = 2, pad = 7) == [0, 0, 0, 1, 1, 0, 0] @test digits(100) == [0, 0, 1] - @test digits(BigInt(2)^128, 2) == [zeros(128); 1] + @test digits(BigInt(2)^128, base = 2) == [zeros(128); 1] let a = zeros(Int, 3) digits!(a, 50) @test a == [0, 5, 0] - digits!(a, 9, 2) + digits!(a, 9, base = 2) @test a == [1, 0, 0] - digits!(a, 7, 2) + digits!(a, 7, base = 2) @test a == [1, 1, 1] end end # Fill a pre allocated 2x4 matrix let a = zeros(Int,(2,4)) for i in 0:3 - digits!(view(a,:,i+1),i,2) + digits!(view(a,:,i+1),i, base = 2) end @test a == [0 1 0 1; 0 0 1 1] @@ -2544,7 +2544,7 @@ for x in [1.23, 7, ℯ, 4//5] #[FP, Int, Irrational, Rat] end function allsubtypes!(m::Module, x::DataType, sts::Set) - for s in names(m, true) + for s in names(m, all = true) if isdefined(m, s) && !Base.isdeprecated(m, s) t = getfield(m, s) if isa(t, Type) && t <: x && t != Union{} diff --git a/test/parse.jl b/test/parse.jl index a510e804ac5e4..6114a6c34a1ef 100644 --- a/test/parse.jl +++ b/test/parse.jl @@ -1,17 +1,17 @@ # This file is a part of Julia. License is MIT: https://julialang.org/license # integer parsing -@test parse(Int32,"0",36) === Int32(0) -@test parse(Int32,"1",36) === Int32(1) -@test parse(Int32,"9",36) === Int32(9) -@test parse(Int32,"A",36) === Int32(10) -@test parse(Int32,"a",36) === Int32(10) -@test parse(Int32,"B",36) === Int32(11) -@test parse(Int32,"b",36) === Int32(11) -@test parse(Int32,"F",36) === Int32(15) -@test parse(Int32,"f",36) === Int32(15) -@test parse(Int32,"Z",36) === Int32(35) -@test parse(Int32,"z",36) === Int32(35) +@test parse(Int32,"0", base = 36) === Int32(0) +@test parse(Int32,"1", base = 36) === Int32(1) +@test parse(Int32,"9", base = 36) === Int32(9) +@test parse(Int32,"A", base = 36) === Int32(10) +@test parse(Int32,"a", base = 36) === Int32(10) +@test parse(Int32,"B", base = 36) === Int32(11) +@test parse(Int32,"b", base = 36) === Int32(11) +@test parse(Int32,"F", base = 36) === Int32(15) +@test parse(Int32,"f", base = 36) === Int32(15) +@test parse(Int32,"Z", base = 36) === Int32(35) +@test parse(Int32,"z", base = 36) === Int32(35) @test parse(Int,"0") == 0 @test parse(Int,"-0") == 0 @@ -24,7 +24,7 @@ @test parse(Int64,"3830974272") == 3830974272 @test parse(Int64,"-3830974272") == -3830974272 @test parse(Int,'3') == 3 -@test parse(Int,'3', 8) == 3 +@test parse(Int,'3', base = 8) == 3 # Issue 20587 for T in vcat(subtypes(Signed), subtypes(Unsigned)) @@ -44,7 +44,7 @@ for T in vcat(subtypes(Signed), subtypes(Unsigned)) end # With a base - result = @test_throws ArgumentError parse(T, s, 16) + result = @test_throws ArgumentError parse(T, s, base = 16) exception_with_base = result.value if T == Bool if s == "" @@ -107,9 +107,9 @@ end @test parse(Bool, "\u202f true") === true @test parse(Bool, "\u202f false") === false -parsebin(s) = parse(Int,s,2) -parseoct(s) = parse(Int,s,8) -parsehex(s) = parse(Int,s,16) +parsebin(s) = parse(Int,s, base = 2) +parseoct(s) = parse(Int,s, base = 8) +parsehex(s) = parse(Int,s, base = 16) @test parsebin("0") == 0 @test parsebin("-0") == 0 @@ -151,12 +151,12 @@ parsehex(s) = parse(Int,s,16) @test parsehex("-10") == -16 @test parsehex("0BADF00D") == 195948557 @test parsehex("-0BADF00D") == -195948557 -@test parse(Int64,"BADCAB1E",16) == 3135023902 -@test parse(Int64,"-BADCAB1E",16) == -3135023902 -@test parse(Int64,"CafeBabe",16) == 3405691582 -@test parse(Int64,"-CafeBabe",16) == -3405691582 -@test parse(Int64,"DeadBeef",16) == 3735928559 -@test parse(Int64,"-DeadBeef",16) == -3735928559 +@test parse(Int64,"BADCAB1E", base = 16) == 3135023902 +@test parse(Int64,"-BADCAB1E", base = 16) == -3135023902 +@test parse(Int64,"CafeBabe", base = 16) == 3405691582 +@test parse(Int64,"-CafeBabe", base = 16) == -3405691582 +@test parse(Int64,"DeadBeef", base = 16) == 3735928559 +@test parse(Int64,"-DeadBeef", base = 16) == -3735928559 @test parse(Int,"2\n") == 2 @test parse(Int," 2 \n ") == 2 @@ -202,7 +202,7 @@ end # issue #15597 # make sure base can be any Integer for T in (Int, BigInt) - let n = parse(T, "123", Int8(10)) + let n = parse(T, "123", base = Int8(10)) @test n == 123 @test isa(n, T) end @@ -214,12 +214,12 @@ end @test parse(Bool, "false") === false @test tryparse(Bool, "true") === true @test tryparse(Bool, "false") === false -@test_throws ArgumentError parse(Int, "2", 1) -@test_throws ArgumentError parse(Int, "2", 63) +@test_throws ArgumentError parse(Int, "2", base = 1) +@test_throws ArgumentError parse(Int, "2", base = 63) # issue #17333: tryparse should still throw on invalid base for T in (Int32, BigInt), base in (0,1,100) - @test_throws ArgumentError tryparse(T, "0", base) + @test_throws ArgumentError tryparse(T, "0", base = base) end # error throwing branch from #10560 diff --git a/test/perf/micro/perf.jl b/test/perf/micro/perf.jl index 01dc45c5a3a99..1792b6525c292 100644 --- a/test/perf/micro/perf.jl +++ b/test/perf/micro/perf.jl @@ -20,7 +20,7 @@ function parseintperf(t) for i=1:t n = rand(UInt32) s = hex(n) - m = UInt32(parse(Int64,s,16)) + m = UInt32(parse(Int64,s, base = 16)) end @test m == n return n diff --git a/test/read.jl b/test/read.jl index cab02db7c7468..80d8c26edb925 100644 --- a/test/read.jl +++ b/test/read.jl @@ -534,15 +534,15 @@ end # mktempdir() do dir @testset "countlines" begin @test countlines(IOBuffer("\n")) == 1 - @test countlines(IOBuffer("\n"),'\r') == 0 + @test countlines(IOBuffer("\n"), eol = '\r') == 0 @test countlines(IOBuffer("\n\n\n\n\n\n\n\n\n\n")) == 10 @test countlines(IOBuffer("\n \n \n \n \n \n \n \n \n \n")) == 10 @test countlines(IOBuffer("\r\n \r\n \r\n \r\n \r\n")) == 5 file = tempname() write(file,"Spiffy header\nspectacular first row\neven better 2nd row\nalmost done\n") @test countlines(file) == 4 - @test countlines(file,'\r') == 0 - @test countlines(file,'\n') == 4 + @test countlines(file, eol = '\r') == 0 + @test countlines(file, eol = '\n') == 4 rm(file) end diff --git a/test/reflection.jl b/test/reflection.jl index a725264a4860a..6c8efecd64d3d 100644 --- a/test/reflection.jl +++ b/test/reflection.jl @@ -251,10 +251,10 @@ let @test Base.binding_module(TestMod7648, :a9475) == TestMod7648.TestModSub9475 @test Base.binding_module(TestMod7648.TestModSub9475, :b9475) == TestMod7648.TestModSub9475 @test Set(names(TestMod7648))==Set([:TestMod7648, :a9475, :foo9475, :c7648, :foo7648, :foo7648_nomethods, :Foo7648]) - @test Set(names(TestMod7648, true)) == Set([:TestMod7648, :TestModSub9475, :a9475, :foo9475, :c7648, :d7648, :f7648, + @test Set(names(TestMod7648, all = true)) == Set([:TestMod7648, :TestModSub9475, :a9475, :foo9475, :c7648, :d7648, :f7648, :foo7648, Symbol("#foo7648"), :foo7648_nomethods, Symbol("#foo7648_nomethods"), :Foo7648, :eval, Symbol("#eval"), :include, Symbol("#include")]) - @test Set(names(TestMod7648, true, true)) == Set([:TestMod7648, :TestModSub9475, :a9475, :foo9475, :c7648, :d7648, :f7648, + @test Set(names(TestMod7648, all = true, imported = true)) == Set([:TestMod7648, :TestModSub9475, :a9475, :foo9475, :c7648, :d7648, :f7648, :foo7648, Symbol("#foo7648"), :foo7648_nomethods, Symbol("#foo7648_nomethods"), :Foo7648, :eval, Symbol("#eval"), :include, Symbol("#include"), :convert, :curmod_name, :curmod]) @@ -578,7 +578,7 @@ function module_depth(from::Module, to::Module) end end function has_backslashes(mod::Module) - for n in names(mod, true, true) + for n in names(mod, all = true, imported = true) isdefined(mod, n) || continue Base.isdeprecated(mod, n) && continue f = getfield(mod, n) diff --git a/test/regex.jl b/test/regex.jl index 4acd9c9269482..67bfd8616dcb8 100644 --- a/test/regex.jl +++ b/test/regex.jl @@ -1,24 +1,24 @@ # This file is a part of Julia. License is MIT: https://julialang.org/license -function collect_eachmatch(re, str, overlap=false) - [m.match for m in collect(eachmatch(re, str, overlap))] +function collect_eachmatch(re, str; overlap=false) + [m.match for m in collect(eachmatch(re, str, overlap = overlap))] end for f in [matchall, collect_eachmatch] @test f(r"a?b?", "asbd") == ["a","","b","",""] == f(r"""a?b?""", "asbd") - @test f(r"a?b?", "asbd", true) == ["a","","b","",""] - @test f(r"\w+", "hello", true) == ["hello","ello","llo","lo","o"] + @test f(r"a?b?", "asbd", overlap=true) == ["a","","b","",""] + @test f(r"\w+", "hello", overlap=true) == ["hello","ello","llo","lo","o"] @test f(r".\s", "x \u2200 x \u2203 y") == ["x ", "∀ ", "x ", "∃ "] @test f(r"(\w+)(\s*)", "The dark side of the moon") == ["The ", "dark ", "side ", "of ", "the ", "moon"] @test f(r"", "") == [""] - @test f(r"", "", true) == [""] + @test f(r"", "", overlap=true) == [""] @test f(r"aa", "aaaa") == ["aa", "aa"] - @test f(r"aa", "aaaa", true) == ["aa", "aa", "aa"] + @test f(r"aa", "aaaa", overlap=true) == ["aa", "aa", "aa"] @test f(r"", "aaa") == ["", "", "", ""] - @test f(r"", "aaa", true) == ["", "", "", ""] + @test f(r"", "aaa", overlap=true) == ["", "", "", ""] @test f(r"GCG","GCGCG") == ["GCG"] - @test f(r"GCG","GCGCG",true) == ["GCG","GCG"] + @test f(r"GCG","GCGCG",overlap=true) == ["GCG","GCG"] end # Issue 8278 diff --git a/test/socket.jl b/test/socket.jl index 582149b5cf489..e629c88e04d56 100644 --- a/test/socket.jl +++ b/test/socket.jl @@ -32,7 +32,7 @@ using Random @test_throws ArgumentError parse(IPv4, "192.") @test ip"::1" == IPv6(1) - @test ip"2605:2700:0:3::4713:93e3" == IPv6(parse(UInt128,"260527000000000300000000471393e3",16)) + @test ip"2605:2700:0:3::4713:93e3" == IPv6(parse(UInt128,"260527000000000300000000471393e3", base = 16)) @test ip"2001:db8:0:0:0:0:2:1" == ip"2001:db8::2:1" == ip"2001:db8::0:2:1" diff --git a/test/strings/basic.jl b/test/strings/basic.jl index 82b012075f2f1..420ef357b307d 100644 --- a/test/strings/basic.jl +++ b/test/strings/basic.jl @@ -64,7 +64,7 @@ end b = 2:62, _ = 1:10 n = (T != BigInt) ? rand(T) : BigInt(rand(Int128)) - @test parse(T, base(b, n), b) == n + @test parse(T, base(b, n), base = b) == n end end end diff --git a/test/strings/util.jl b/test/strings/util.jl index 3ac1eb7edbdd1..ef4dc13b31a6c 100644 --- a/test/strings/util.jl +++ b/test/strings/util.jl @@ -269,23 +269,23 @@ end @test chop("fooε") == "foo" @test chop("foεo") == "foε" @test chop("∃∃∃∃") == "∃∃∃" - @test chop("∀ϵ∃Δ", 0, 0) == "∀ϵ∃Δ" - @test chop("∀ϵ∃Δ", 0, 1) == "∀ϵ∃" - @test chop("∀ϵ∃Δ", 0, 2) == "∀ϵ" - @test chop("∀ϵ∃Δ", 0, 3) == "∀" - @test chop("∀ϵ∃Δ", 0, 4) == "" - @test chop("∀ϵ∃Δ", 0, 5) == "" - @test chop("∀ϵ∃Δ", 1, 0) == "ϵ∃Δ" - @test chop("∀ϵ∃Δ", 2, 0) == "∃Δ" - @test chop("∀ϵ∃Δ", 3, 0) == "Δ" - @test chop("∀ϵ∃Δ", 4, 0) == "" - @test chop("∀ϵ∃Δ", 5, 0) == "" - @test chop("∀ϵ∃Δ", 1, 1) == "ϵ∃" - @test chop("∀ϵ∃Δ", 2, 2) == "" - @test chop("∀ϵ∃Δ", 3, 3) == "" - @test_throws ArgumentError chop("∀ϵ∃Δ", -3, 3) - @test_throws ArgumentError chop("∀ϵ∃Δ", 3, -3) - @test_throws ArgumentError chop("∀ϵ∃Δ", -3, -3) + @test chop("∀ϵ∃Δ", head=0, tail=0) == "∀ϵ∃Δ" + @test chop("∀ϵ∃Δ", head=0, tail=1) == "∀ϵ∃" + @test chop("∀ϵ∃Δ", head=0, tail=2) == "∀ϵ" + @test chop("∀ϵ∃Δ", head=0, tail=3) == "∀" + @test chop("∀ϵ∃Δ", head=0, tail=4) == "" + @test chop("∀ϵ∃Δ", head=0, tail=5) == "" + @test chop("∀ϵ∃Δ", head=1, tail=0) == "ϵ∃Δ" + @test chop("∀ϵ∃Δ", head=2, tail=0) == "∃Δ" + @test chop("∀ϵ∃Δ", head=3, tail=0) == "Δ" + @test chop("∀ϵ∃Δ", head=4, tail=0) == "" + @test chop("∀ϵ∃Δ", head=5, tail=0) == "" + @test chop("∀ϵ∃Δ", head=1, tail=1) == "ϵ∃" + @test chop("∀ϵ∃Δ", head=2, tail=2) == "" + @test chop("∀ϵ∃Δ", head=3, tail=3) == "" + @test_throws ArgumentError chop("∀ϵ∃Δ", head=-3, tail=3) + @test_throws ArgumentError chop("∀ϵ∃Δ", head=3, tail=-3) + @test_throws ArgumentError chop("∀ϵ∃Δ", head=-3, tail=-3) @test isa(chomp("foo"), SubString) @test isa(chop("foo"), SubString)