Skip to content

Commit

Permalink
keywords unlocked
Browse files Browse the repository at this point in the history
  • Loading branch information
bramtayl authored and JeffBezanson committed Jan 20, 2018
1 parent 625923f commit f219762
Show file tree
Hide file tree
Showing 58 changed files with 261 additions and 235 deletions.
31 changes: 25 additions & 6 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -1575,7 +1575,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

Expand Down Expand Up @@ -1614,6 +1615,24 @@ export readandwrite
# PR #25196
@deprecate_binding ObjectIdDict IdDict{Any,Any}

@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
Expand Down
2 changes: 1 addition & 1 deletion base/docs/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,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

Expand Down
20 changes: 10 additions & 10 deletions base/event.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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)
Expand All @@ -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
Expand Down
24 changes: 14 additions & 10 deletions base/file.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,37 +81,44 @@ 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
directory. If the directory already exists, or some intermediate directories do not exist,
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
Expand All @@ -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)
Expand Down
25 changes: 13 additions & 12 deletions base/intfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -747,27 +747,27 @@ 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
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
Expand All @@ -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

"""
Expand All @@ -792,22 +793,22 @@ 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
the array length. If the array length is excessive, the excess portion is filled with zeros.
# 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
Expand All @@ -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"))
Expand Down
8 changes: 4 additions & 4 deletions base/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,7 @@ function skipchars(io::IO, pred; 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
Expand All @@ -962,11 +962,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)
Expand All @@ -980,4 +980,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
6 changes: 3 additions & 3 deletions base/iobuffer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -115,17 +115,17 @@ 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.
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,
Expand Down
2 changes: 1 addition & 1 deletion base/libgit2/blob.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

"""
Expand Down
4 changes: 2 additions & 2 deletions base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ macro return_if_file(path)
end

function find_package(name::String)
endswith(name, ".jl") && (name = chop(name, 0, 3))
endswith(name, ".jl") && (name = chop(name, tail = 3))
for dir in [Pkg.dir(); LOAD_PATH]
dir = abspath(dir)
@return_if_file joinpath(dir, "$name.jl")
Expand Down Expand Up @@ -598,7 +598,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
Expand Down
4 changes: 2 additions & 2 deletions base/mpfr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit f219762

Please sign in to comment.