Skip to content

Commit

Permalink
Drop compat code for range with kw args and LinRange from #511
Browse files Browse the repository at this point in the history
  • Loading branch information
martinholters committed Oct 8, 2019
1 parent 3dc84cd commit 1fb0364
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 47 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]).

Expand Down Expand Up @@ -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]).

Expand Down
34 changes: 1 addition & 33 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions test/old.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 0 additions & 10 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 1fb0364

Please sign in to comment.