From ef9891dc2bef90e1cdb37f86dfeb475554d3a26c Mon Sep 17 00:00:00 2001 From: Martin Holters Date: Wed, 5 Sep 2018 15:27:38 +0100 Subject: [PATCH] Remove a bunch of definitions only relevant prior to Julia 0.6 (#628) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Remove `take!(::Task)` definition for Julia versions prior to 0.6 Was added in #307. * Remove `redirect_std*(f, stream)` definitions for Julia prior to v0.6 Were added in #275. * Remove at-__DIR__ macro definition for Julia versions prior to 0.6 Was added in #281. * Remove `broadcast` definition for equal-length tuples Was added in #324 and #328 * Remove definitions of `unsafe_get` and `isnull` fallsback Were added in #287. * Remove defintions of `xor` and `⊻` Were added in #289. * Definitions of `numerator` and `denominator` Were added in #290. * Remove defintion of `iszero` Was added in #305. * Remove definition of `>:` Was added in #336 * Remove definition of `take!(::Base.AbstractIOBuffer)` Was added in #290. * Remove definiton of `.&` and `.|` Were added in #306. * Remove definition of `Compat.isapprox` Was added in #309. --- README.md | 37 --------- src/Compat.jl | 90 --------------------- test/runtests.jl | 206 ----------------------------------------------- 3 files changed, 333 deletions(-) diff --git a/README.md b/README.md index 1da1280a2..7200d8763 100644 --- a/README.md +++ b/README.md @@ -122,35 +122,17 @@ Currently, the `@compat` macro supports the following syntaxes: * [`normalize`](http://docs.julialang.org/en/latest/stdlib/linalg/?highlight=normalize#Base.normalize) and [`normalize!`](http://docs.julialang.org/en/latest/stdlib/linalg/?highlight=normalize#Base.normalize!), normalizes a vector with respect to the p-norm ([#13681]) -* `redirect_stdout`, `redirect_stderr`, and `redirect_stdin` take an optional function as a first argument, `redirect_std*(f, stream)`, so that one may use `do` block syntax (as first available for Julia 0.6) - -* `unsafe_get` returns the `:value` field of a `Nullable` object without any null-check and has a generic fallback for non-`Nullable` argument ([#18484]) - -* `isnull` has a generic fallback for non-`Nullable` argument - * `transcode` converts between UTF-xx string encodings in Julia 0.5 (as a lightweight alternative to the LegacyStrings package) ([#17323]) -* `>:`, a supertype operator for symmetry with `issubtype` (`A >: B` is equivalent to `B <: A`), can be used in 0.5 and earlier ([#20407]). - -* `iszero(x)` efficiently checks whether `x == zero(x)` (including arrays) can be used in 0.5 and earlier ([#19950]). - -* `.&` and `.|` are short syntax for `broadcast(&, xs...)` and `broadcast(|, xs...)` (respectively) in Julia 0.6 (only supported on Julia 0.5 and above) ([#17623]) - -* `Compat.isapprox` with `nans` keyword argument ([#20022]) - * `Compat.readline` with `keep` keyword argument ([#25646]) * `Compat.eachline` with `keep` keyword argument ([#25646]) * `Compat.readuntil` with `keep` keyword argument ([#25646]) -* `take!` method for `Task`s since some functions now return `Channel`s instead of `Task`s ([#19841]) - * The `isabstract`, `parameter_upper_bound`, `typename` reflection methods were added in Julia 0.6. This package re-exports these from the `Compat.TypeUtils` submodule. On earlier versions of julia, that module contains the same functions, but operating on the pre-0.6 type system representation. -* `broadcast` is supported on tuples of the same lengths on 0.5. ([#16986]) - * `zeros` and `ones` support an interface the same as `similar` ([#19635]) * `convert` can convert between different `Set` types on 0.5 and below. ([#18727]) @@ -283,12 +265,6 @@ Currently, the `@compat` macro supports the following syntaxes: * `reprmime(mime, x)` is now `repr(mime, x)` ([#25990]) and `mimewritable` is now `showable` ([#26089]). -* `$` is now `xor` or `⊻` ([#18977]) - -* `num` and `den` are now `numerator` and `denominator` ([#19246]) - -* `takebuf_array` is now a method of `take!`. `takebuf_string(io)` becomes `String(take!(io))` ([#19088]) - * `is_apple`, `is_bsd`, `is_linux`, `is_unix`, and `is_windows` are now `Sys.isapple`, `Sys.isbsd`, `Sys.islinux`, `Sys.isunix`, and `Sys.iswindows`, respectively. These are available in the `Compat.Sys` submodule. ([#22182]) @@ -403,8 +379,6 @@ Currently, the `@compat` macro supports the following syntaxes: ## New macros -* `@__DIR__` has been added ([#18380]) - * `@vectorize_1arg` and `@vectorize_2arg` are deprecated on Julia 0.6 in favor of the broadcast syntax ([#17302]). `Compat.@dep_vectorize_1arg` and `Compat.@dep_vectorize_2arg` are provided so that packages can still provide @@ -488,26 +462,15 @@ includes this fix. Find the minimum version from there. `Compat ` [#13681]: https://github.com/JuliaLang/julia/issues/13681 -[#16986]: https://github.com/JuliaLang/julia/issues/16986 [#17302]: https://github.com/JuliaLang/julia/issues/17302 [#17323]: https://github.com/JuliaLang/julia/issues/17323 -[#17623]: https://github.com/JuliaLang/julia/issues/17623 [#18082]: https://github.com/JuliaLang/julia/issues/18082 -[#18380]: https://github.com/JuliaLang/julia/issues/18380 -[#18484]: https://github.com/JuliaLang/julia/issues/18484 [#18629]: https://github.com/JuliaLang/julia/issues/18629 [#18727]: https://github.com/JuliaLang/julia/issues/18727 -[#18977]: https://github.com/JuliaLang/julia/issues/18977 -[#19088]: https://github.com/JuliaLang/julia/issues/19088 -[#19246]: https://github.com/JuliaLang/julia/issues/19246 [#19449]: https://github.com/JuliaLang/julia/issues/19449 [#19635]: https://github.com/JuliaLang/julia/issues/19635 [#19784]: https://github.com/JuliaLang/julia/issues/19784 -[#19841]: https://github.com/JuliaLang/julia/issues/19841 -[#19950]: https://github.com/JuliaLang/julia/issues/19950 [#20005]: https://github.com/JuliaLang/julia/issues/20005 -[#20022]: https://github.com/JuliaLang/julia/issues/20022 -[#20407]: https://github.com/JuliaLang/julia/issues/20407 [#20974]: https://github.com/JuliaLang/julia/issues/20974 [#21197]: https://github.com/JuliaLang/julia/issues/21197 [#21346]: https://github.com/JuliaLang/julia/issues/21346 diff --git a/src/Compat.jl b/src/Compat.jl index 0eda7c595..15b9a49ea 100644 --- a/src/Compat.jl +++ b/src/Compat.jl @@ -72,10 +72,6 @@ end export @nospecialize end -if VERSION < v"0.6.0-dev.2043" - Base.take!(t::Task) = consume(t) -end - # https://github.com/JuliaLang/julia/pull/22064 @static if !isdefined(Base, Symbol("@__MODULE__")) # 0.7 @@ -91,24 +87,6 @@ end eval(mod, :(include_string($code, $fname))) end -import Base: redirect_stdin, redirect_stdout, redirect_stderr -if VERSION < v"0.6.0-dev.374" - for (F,S) in ((:redirect_stdin, :STDIN), (:redirect_stdout, :STDOUT), (:redirect_stderr, :STDERR)) - @eval function $F(f::Function, stream) - STDOLD = $S - $F(stream) - try f() finally $F(STDOLD) end - end - end -end - -@static if VERSION < v"0.6.0-dev.528" - macro __DIR__() - Base.source_dir() - end - export @__DIR__ -end - # PR #17302 # Provide a non-deprecated version of `@vectorize_(1|2)arg` macro which defines # deprecated version of the function so that the depwarns can be fixed without @@ -164,74 +142,6 @@ else end end -# broadcast over same length tuples, from julia#16986 -@static if VERSION < v"0.6.0-dev.693" - Base.Broadcast.broadcast{N}(f, t::NTuple{N}, ts::Vararg{NTuple{N}}) = map(f, t, ts...) -end - -# julia#18484 -@static if VERSION < v"0.6.0-dev.848" - unsafe_get(x::Nullable) = x.value - unsafe_get(x) = x - export unsafe_get - Base.isnull(x) = false -end - -# julia#18977 -@static if !isdefined(Base, :xor) - # 0.6 - const xor = $ - const ⊻ = xor - export xor, ⊻ -end - -# julia#19246 -@static if !isdefined(Base, :numerator) - # 0.6 - const numerator = num - const denominator = den - export numerator, denominator -end - -# julia #19950 -@static if !isdefined(Base, :iszero) - # 0.6 - iszero(x) = x == zero(x) - iszero(x::Number) = x == 0 - iszero(x::AbstractArray) = all(iszero, x) - export iszero -end - -# julia #20407 -@static if !isdefined(Base, :(>:)) - # 0.6 - const >: = let - _issupertype(a::ANY, b::ANY) = issubtype(b, a) - end - export >: -end - -# julia#19088 -if VERSION < v"0.6.0-dev.1256" - Base.take!(io::Base.AbstractIOBuffer) = takebuf_array(io) -end - -if VERSION < v"0.6.0-dev.1632" - # To work around unsupported syntax on Julia 0.4 - include_string("export .&, .|") - include_string(".&(xs...) = broadcast(&, xs...)") - include_string(".|(xs...) = broadcast(|, xs...)") -end - -@static if VERSION < v"0.6.0-dev.2093" # Compat.isapprox to allow for NaNs - using Base.rtoldefault - function isapprox(x::Number, y::Number; rtol::Real=rtoldefault(x,y), atol::Real=0, nans::Bool=false) - x == y || (isfinite(x) && isfinite(y) && abs(x-y) <= atol + rtol*max(abs(x), abs(y))) || (nans && isnan(x) && isnan(y)) - end -else - import Base.isapprox -end - @static if !isdefined(Base, :isabstracttype) # VERSION < v"0.7.0-DEV.3475" const isabstracttype = Base.isabstract export isabstracttype diff --git a/test/runtests.jl b/test/runtests.jl index d3c376306..097495626 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -7,110 +7,6 @@ using Compat.SparseArrays const struct_sym = VERSION < v"0.7.0-DEV.1263" ? :type : :struct -# Issue #291 -# 0.6 -@test (1, 2) == @compat abs.((1, -2)) -@test broadcast(+, (1.0, 1.0), (0, -2.0)) == (1.0,-1.0) - -# Test for `take!(::Task)`/`take!(::Channel)` -# 0.6 -dirwalk = mktempdir() -cd(dirwalk) do - for i=1:2 - mkdir("sub_dir$i") - open("file$i", "w") do f end - - mkdir(joinpath("sub_dir1", "subsub_dir$i")) - touch(joinpath("sub_dir1", "file$i")) - end - touch(joinpath("sub_dir2", "file_dir2")) - has_symlinks = Compat.Sys.isunix() ? true : (isdefined(Base, :WINDOWS_VISTA_VER) && Base.windows_version() >= Base.WINDOWS_VISTA_VER) - follow_symlink_vec = has_symlinks ? [true, false] : [false] - has_symlinks && symlink(abspath("sub_dir2"), joinpath("sub_dir1", "link")) - for follow_symlinks in follow_symlink_vec - chnl = walkdir(".", follow_symlinks=follow_symlinks) - root, dirs, files = take!(chnl) - @test root == "." - @test dirs == ["sub_dir1", "sub_dir2"] - @test files == ["file1", "file2"] - - root, dirs, files = take!(chnl) - @test root == joinpath(".", "sub_dir1") - @test dirs == (has_symlinks ? ["link", "subsub_dir1", "subsub_dir2"] : ["subsub_dir1", "subsub_dir2"]) - @test files == ["file1", "file2"] - - root, dirs, files = take!(chnl) - if follow_symlinks - @test root == joinpath(".", "sub_dir1", "link") - @test dirs == [] - @test files == ["file_dir2"] - root, dirs, files = take!(chnl) - end - for i=1:2 - @test root == joinpath(".", "sub_dir1", "subsub_dir$i") - @test dirs == [] - @test files == [] - root, dirs, files = take!(chnl) - end - - @test root == joinpath(".", "sub_dir2") - @test dirs == [] - @test files == ["file_dir2"] - end - - for follow_symlinks in follow_symlink_vec - chnl = walkdir(".", follow_symlinks=follow_symlinks, topdown=false) - root, dirs, files = take!(chnl) - if follow_symlinks - @test root == joinpath(".", "sub_dir1", "link") - @test dirs == [] - @test files == ["file_dir2"] - root, dirs, files = take!(chnl) - end - for i=1:2 - @test root == joinpath(".", "sub_dir1", "subsub_dir$i") - @test dirs == [] - @test files == [] - root, dirs, files = take!(chnl) - end - @test root == joinpath(".", "sub_dir1") - @test dirs == (has_symlinks ? ["link", "subsub_dir1", "subsub_dir2"] : ["subsub_dir1", "subsub_dir2"]) - @test files == ["file1", "file2"] - - root, dirs, files = take!(chnl) - @test root == joinpath(".", "sub_dir2") - @test dirs == [] - @test files == ["file_dir2"] - - root, dirs, files = take!(chnl) - @test root == "." - @test dirs == ["sub_dir1", "sub_dir2"] - @test files == ["file1", "file2"] - end - #test of error handling - chnl_error = walkdir(".") - chnl_noerror = walkdir(".", onerror=x->x) - root, dirs, files = take!(chnl_error) - @test root == "." - @test dirs == ["sub_dir1", "sub_dir2"] - @test files == ["file1", "file2"] - - rm(joinpath("sub_dir1"), recursive=true) - @test_throws SystemError take!(chnl_error) # throws an error because sub_dir1 do not exist - - root, dirs, files = take!(chnl_noerror) - @test root == "." - @test dirs == ["sub_dir1", "sub_dir2"] - @test files == ["file1", "file2"] - - root, dirs, files = take!(chnl_noerror) # skips sub_dir1 as it no longer exist - @test root == joinpath(".", "sub_dir2") - @test dirs == [] - @test files == ["file_dir2"] - -end -rm(dirwalk, recursive=true) - for os in [:apple, :bsd, :linux, :unix, :windows] from_base = if VERSION >= v"0.7.0-DEV.914" Expr(:., Expr(:., :Base, Base.Meta.quot(:Sys)), Base.Meta.quot(Symbol("is", os))) @@ -120,37 +16,6 @@ for os in [:apple, :bsd, :linux, :unix, :windows] @eval @test Compat.Sys.$(Symbol("is", os))() == $from_base() end -# do-block redirect_std* -# 0.6 -let filename = tempname() - ret = open(filename, "w") do f - redirect_stdout(f) do - println("hello") - [1,3] - end - end - @test ret == [1,3] - @test chomp(read(filename, String)) == "hello" - ret = open(filename, "w") do f - redirect_stderr(f) do - println(stderr, "WARNING: hello") - [2] - end - end - @test ret == [2] - @test occursin("WARNING: hello", read(filename, String)) - ret = open(filename) do f - redirect_stdin(f) do - readline() - end - end - @test occursin("WARNING: hello", ret) - rm(filename) -end - -# 0.6 -@test @__DIR__() == dirname(@__FILE__) - # PR #17302 # To be removed when 0.6 support is dropped. f17302(a::Number) = a @@ -175,52 +40,6 @@ else end end -if VERSION < v"0.7.0-DEV.3017" - types = [ - Bool, - Float16, - Float32, - Float64, - Int128, - Int16, - Int32, - Int64, - Int8, - UInt16, - UInt32, - UInt64, - UInt8, - ] - for T in types - # julia#18484, generic isnull, unsafe_get - a = one(T) - x = Nullable(a, true) - @test isequal(unsafe_get(x), a) - - x = Nullable{Array{T}}() - @test_throws UndefRefError unsafe_get(x) - end -end - -@test xor(1,5) == 4 -@test 1 ⊻ 5 == 4 - -# supertype operator -@test !(Int >: Integer) -@test Integer >: Int - -# julia#19246 -@test numerator(1//2) === 1 -@test denominator(1//2) === 2 - -# julia#19088 -let io = IOBuffer() - write(io, "aaa") - @test take!(io) == UInt8['a', 'a', 'a'] - write(io, "bbb") - @test String(take!(io)) == "bbb" -end - let s = "Koala test: 🐨" @test transcode(UInt16, s) == UInt16[75,111,97,108,97,32,116,101,115,116,58,32,55357,56360] @test transcode(UInt32, s) == UInt32[75,111,97,108,97,32,116,101,115,116,58,32,128040] @@ -231,22 +50,6 @@ let s = "Koala test: 🐨" end end -# julia#19950, tests from Base (#20028) -for T in (Float16, Float32, Float64, BigFloat, Int8, Int16, Int32, Int64, Int128, - BigInt, UInt8, UInt16, UInt32, UInt64, UInt128) - @test iszero(T(0)) - @test iszero(Complex{T}(0)) - if T<:Integer - @test iszero(Rational{T}(0)) - end - if T<:AbstractFloat - @test iszero(T(-0.0)) - @test iszero(Complex{T}(-0.0)) - end -end -@test !iszero([0, 1, 2, 3]) -@test iszero([0, 0, 0, 0]) - let x = view(1:10, 2:4) D = Diagonal(x) @@ -257,15 +60,6 @@ let @test A*D == copy(A) * Diagonal(copy(x)) end -# julia#17623 -# 0.6 -@test [true, false] .& [true, true] == [true, false] -@test [true, false] .| [true, true] == [true, true] - -# julia#20022 -@test !Compat.isapprox(NaN, NaN) -@test Compat.isapprox(NaN, NaN, nans=true) - # julia#13998 for x in (3.1, -17, 3//4, big(111.1), Inf) local x