diff --git a/README.md b/README.md index 5f7cbccdc..dcab75107 100644 --- a/README.md +++ b/README.md @@ -70,7 +70,7 @@ Currently, the `@compat` macro supports the following syntaxes: * Three-argument methods `prevind(s,i,n)`, `nextind(s,i,n)` ([#23805]), and `length(s,i,j)` ([#24999]); the latter two replace `chr2ind` and `ind2chr` in Julia 0.7, respectively. -* `Compat.range` supporting positional and keyword arguments flavors ([#25896]), ([#28708]). +* `range` supporting `stop` as positional argument ([#28708]). * `Compat.mv` and `Compat.cp` with `force` keyword argument ([#26069]). @@ -113,8 +113,6 @@ Currently, the `@compat` macro supports the following syntaxes: for entries with no match and gives the index of the first (rather than the last) match ([#25662], [#25998]). -* `LinSpace` is now `LinRange` ([#25896]). - * `isupper`, `islower`, `ucfirst` and `lcfirst` are now `isuppercase`, `islowercase`, `uppercasefirst` and `lowercasefirst` ([#26442]). diff --git a/src/Compat.jl b/src/Compat.jl index a01c7617d..643f056f2 100644 --- a/src/Compat.jl +++ b/src/Compat.jl @@ -76,38 +76,6 @@ end end end -@static if VERSION < v"0.7.0-DEV.3986" - const LinRange = Base.LinSpace - export LinRange - - function range(start; step=nothing, stop=nothing, length=nothing) - have_step = step !== nothing - have_stop = stop !== nothing - have_length = length !== nothing - - if !(have_stop || have_length) - throw(ArgumentError("At least one of `length` or `stop` must be specified")) - elseif have_step && have_stop && have_length - throw(ArgumentError("Too many arguments specified; try passing only one of `stop` or `length`")) - elseif start === nothing - throw(ArgumentError("Can't start a range at `nothing`")) - end - - if have_stop && !have_length - return have_step ? (start:step:stop) : (start:stop) - elseif have_length && !have_stop - return have_step ? Base.range(start, step, length) : Base.range(start, length) - elseif !have_step - return linspace(start, stop, length) - end - end -elseif VERSION < v"1.0.0-DEV.57" - import Base: LinRange - range(start; kwargs...) = Base.range(start; kwargs...) -else - import Base: range # import as it is further extended below -end - @static if VERSION < v"0.7.0-DEV.3995" cp(src::AbstractString, dst::AbstractString; force::Bool=false, follow_symlinks::Bool=false) = Base.cp(src, dst; remove_destination = force, follow_symlinks = follow_symlinks) @@ -419,7 +387,7 @@ function rangedepwarn(;step=nothing, length=nothing, kwargs...) end if VERSION < v"1.1.0-DEV.506" - function range(start, stop; kwargs...) + function Base.range(start, stop; kwargs...) rangedepwarn(;kwargs...) range(start; stop=stop, kwargs...) end diff --git a/src/deprecated.jl b/src/deprecated.jl index 4b1488b03..e0d937245 100644 --- a/src/deprecated.jl +++ b/src/deprecated.jl @@ -73,7 +73,7 @@ if VERSION >= v"1.1.0-DEV.506" # deprecation of range(start, stop) for earlier versions is done in Compat.jl # This method is restricted to Number, since we don't # want to overwrite the (::Any, ::Any) method in Base. - function range(start::Number, stop::Number; kwargs...) + function Base.range(start::Number, stop::Number; kwargs...) rangedepwarn(;kwargs...) range(start; stop=stop, kwargs...) end diff --git a/test/old.jl b/test/old.jl index 9025dee09..9c0da97ab 100644 --- a/test/old.jl +++ b/test/old.jl @@ -834,3 +834,13 @@ let buf = Compat.IOBuffer(sizehint=20) println(buf, "Hello world.") @test String(take!(buf)) == "Hello world.\n" end + +# 0.7.0-DEV.3986 +@test_throws ArgumentError Compat.range(1) +@test_throws ArgumentError Compat.range(nothing) +@test_throws ArgumentError Compat.range(1, step=1) +@test_throws ArgumentError Compat.range(1, step=1, stop=4, length=3) +@test Compat.range(2, step=2, stop=8) == 2:2:8 +@test Compat.range(2, stop=8) == 2:8 +@test Compat.range(2, step=2, length=8) == 2:2:16 +@test Compat.range(1.0, stop=2.0, length=3) == 1.0:0.5:2.0 diff --git a/test/runtests.jl b/test/runtests.jl index 13a4f345e..5b58598ce 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -82,16 +82,6 @@ end @test codeunit("foo") == codeunit(SubString("fooαβγ",1,3)) == UInt8 -# 0.7.0-DEV.3986 -@test_throws ArgumentError Compat.range(1) -@test_throws ArgumentError Compat.range(nothing) -@test_throws ArgumentError Compat.range(1, step=1) -@test_throws ArgumentError Compat.range(1, step=1, stop=4, length=3) -@test Compat.range(2, step=2, stop=8) == 2:2:8 -@test Compat.range(2, stop=8) == 2:8 -@test Compat.range(2, step=2, length=8) == 2:2:16 -@test Compat.range(1.0, stop=2.0, length=3) == 1.0:0.5:2.0 - # 0.7.0-DEV.3995 mktempdir(@__DIR__) do dir src = joinpath(dir, "src.jl")