From c08c8a7a5405b5baddc4f87853ab81d4f71ff96c Mon Sep 17 00:00:00 2001 From: Martin Holters Date: Tue, 8 Oct 2019 17:49:14 +0200 Subject: [PATCH] Drop compat code for `Compat.round` and friends #500, #530, and #537 --- README.md | 3 --- src/Compat.jl | 52 ----------------------------------------------- src/deprecated.jl | 6 ++++++ test/old.jl | 20 ++++++++++++++++++ test/runtests.jl | 20 ------------------ 5 files changed, 26 insertions(+), 75 deletions(-) diff --git a/README.md b/README.md index f23d175be..a86e691e0 100644 --- a/README.md +++ b/README.md @@ -76,9 +76,6 @@ Currently, the `@compat` macro supports the following syntaxes: * `Compat.range` supporting positional and keyword arguments flavors ([#25896]), ([#28708]). -* `Compat.trunc`, `Compat.floor`, `Compat.ceil`, `Compat.round`, take a keyword argument - for `base` and `digits`, `Compat.round` also takes `sigdigits` ([#26156], [#26670]). - * `Compat.mv` and `Compat.cp` with `force` keyword argument ([#26069]). * `Compat.accumulate`, `Compat.accumulate!`, `Compat.all`, `Compat.any`, diff --git a/src/Compat.jl b/src/Compat.jl index 881c6a569..442596490 100644 --- a/src/Compat.jl +++ b/src/Compat.jl @@ -76,58 +76,6 @@ end end end -# https://github.com/JuliaLang/julia/pull/26670 -@static if VERSION < v"0.7.0-DEV.4062" - trunc(x; digits = 0, base = 10) = Base.trunc(x, digits, base) - floor(x; digits = 0, base = 10) = Base.floor(x, digits, base) - ceil(x; digits = 0, base = 10) = Base.ceil(x, digits, base) - function round(x; digits = nothing, sigdigits = nothing, base = 10) - if digits === nothing - if sigdigits === nothing - Base.round(x, 0, base) - else - Base.signif(x, sigdigits, base) - end - else - sigdigits === nothing || throw(AgrumentError("`round` cannot use both `digits` and `sigdigits` arguments")) - Base.round(x, digits, base) - end - end -elseif VERSION < v"0.7.0-DEV.4804" - trunc(x; digits = 0, base = 10) = Base.trunc(x, digits, base = base) - floor(x; digits = 0, base = 10) = Base.floor(x, digits, base = base) - ceil(x; digits = 0, base = 10) = Base.ceil(x, digits, base = base) - function round(x; digits = nothing, sigdigits = nothing, base = 10) - if digits === nothing - if sigdigits === nothing - Base.round(x, 0, base = base) - else - Base.signif(x, sigdigits, base = base) - end - else - sigdigits === nothing || throw(AgrumentError("`round` cannot use both `digits` and `sigdigits` arguments")) - Base.round(x, digits, base = base) - end - end -elseif VERSION < v"0.7.0-beta2.86" - # https://github.com/JuliaLang/julia/pull/28199 - trunc(x; digits = 0, base = 10) = Base.trunc(x, digits = digits, base = base) - floor(x; digits = 0, base = 10) = Base.floor(x, digits = digits, base = base) - ceil(x; digits = 0, base = 10) = Base.ceil(x, digits = digits, base = base) - function round(x; digits = nothing, sigdigits = nothing, base = 10) - if digits === nothing && sigdigits === nothing - Base.round(x, digits = 0, base = base) - else - Base.round(x, digits = digits, sigdigits = sigdigits, base = base) - end - end -else - trunc(x; digits = 0, base = 10) = Base.trunc(x, digits = digits, base = base) - floor(x; digits = 0, base = 10) = Base.floor(x, digits = digits, base = base) - ceil(x; digits = 0, base = 10) = Base.ceil(x, digits = digits, base = base) - round(x; digits = nothing, sigdigits = nothing, base = 10) = Base.round(x, digits = digits, sigdigits = sigdigits, base = base) -end - # https://github.com/JuliaLang/julia/pull/25872 if VERSION < v"0.7.0-DEV.3734" if isdefined(Base, :open_flags) diff --git a/src/deprecated.jl b/src/deprecated.jl index e76dc980f..4b1488b03 100644 --- a/src/deprecated.jl +++ b/src/deprecated.jl @@ -62,6 +62,12 @@ Base.@deprecate floor(x, digits; base = 10) Compat.floor(x, digits = digits, bas Base.@deprecate ceil(x, digits; base = 10) Compat.ceil(x, digits = digits, base = base) false Base.@deprecate round(x, digits; base = 10) Compat.round(x, digits = digits, base = base) false Base.@deprecate signif(x, digits; base = 10) Compat.round(x, sigdigits = digits, base = base) false +# standard methods from Base; can be removed (so that Compat just inherits the functions +# from Base) once above deprecations are removed +trunc(x; digits = 0, base = 10) = Base.trunc(x, digits = digits, base = base) +floor(x; digits = 0, base = 10) = Base.floor(x, digits = digits, base = base) +ceil(x; digits = 0, base = 10) = Base.ceil(x, digits = digits, base = base) +round(x; digits = nothing, sigdigits = nothing, base = 10) = Base.round(x, digits = digits, sigdigits = sigdigits, base = base) if VERSION >= v"1.1.0-DEV.506" # deprecation of range(start, stop) for earlier versions is done in Compat.jl diff --git a/test/old.jl b/test/old.jl index f2efccfe5..77aa6770d 100644 --- a/test/old.jl +++ b/test/old.jl @@ -799,3 +799,23 @@ module TestNames end @test :foo in Compat.names(TestNames) @test :bar in Compat.names(TestNames, all=true) + +# 0.7.0-DEV.4804 +@test Compat.trunc(pi) == 3.0 +@test Compat.floor(pi) == 3.0 +@test Compat.ceil(pi) == 4.0 +@test Compat.round(pi) == 3.0 +@test Compat.trunc(pi, digits = 3) == 3.141 +@test Compat.floor(pi, digits = 3) == 3.141 +@test Compat.ceil(pi, digits = 3) == 3.142 +@test Compat.round(pi, digits = 3) == 3.142 +@test Compat.round(pi, sigdigits = 5) == 3.1416 +@test Compat.trunc(pi, base = 2) == 3.0 +@test Compat.floor(pi, base = 2) == 3.0 +@test Compat.ceil(pi, base = 2) == 4.0 +@test Compat.round(pi, base = 2) == 3.0 +@test Compat.trunc(pi, digits = 3, base = 2) == 3.125 +@test Compat.floor(pi, digits = 3, base = 2) == 3.125 +@test Compat.ceil(pi, digits = 3, base = 2) == 3.25 +@test Compat.round(pi, digits = 3, base = 2) == 3.125 +@test Compat.round(pi, sigdigits = 5, base = 2) == 3.125 diff --git a/test/runtests.jl b/test/runtests.jl index 551176cf1..d25db015c 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -82,26 +82,6 @@ end @test codeunit("foo") == codeunit(SubString("fooαβγ",1,3)) == UInt8 -# 0.7.0-DEV.4804 -@test Compat.trunc(pi) == 3.0 -@test Compat.floor(pi) == 3.0 -@test Compat.ceil(pi) == 4.0 -@test Compat.round(pi) == 3.0 -@test Compat.trunc(pi, digits = 3) == 3.141 -@test Compat.floor(pi, digits = 3) == 3.141 -@test Compat.ceil(pi, digits = 3) == 3.142 -@test Compat.round(pi, digits = 3) == 3.142 -@test Compat.round(pi, sigdigits = 5) == 3.1416 -@test Compat.trunc(pi, base = 2) == 3.0 -@test Compat.floor(pi, base = 2) == 3.0 -@test Compat.ceil(pi, base = 2) == 4.0 -@test Compat.round(pi, base = 2) == 3.0 -@test Compat.trunc(pi, digits = 3, base = 2) == 3.125 -@test Compat.floor(pi, digits = 3, base = 2) == 3.125 -@test Compat.ceil(pi, digits = 3, base = 2) == 3.25 -@test Compat.round(pi, digits = 3, base = 2) == 3.125 -@test Compat.round(pi, sigdigits = 5, base = 2) == 3.125 - # 0.7.0-DEV.3734 let buf = Compat.IOBuffer(read=true, write=false, maxsize=25) @test buf.readable