From 89740ef760491dc62df07ae2a3a4053a86fd1971 Mon Sep 17 00:00:00 2001 From: Curtis Vogt Date: Thu, 7 Dec 2017 02:03:52 -0600 Subject: [PATCH] Support get(::Function, ::EnvHash, key) (#430) --- README.md | 3 +++ src/Compat.jl | 7 +++++++ test/runtests.jl | 6 ++++++ 3 files changed, 16 insertions(+) diff --git a/README.md b/README.md index cafd1ddb1a8ad..db55f2da4402d 100644 --- a/README.md +++ b/README.md @@ -201,6 +201,8 @@ Currently, the `@compat` macro supports the following syntaxes: * `IOContext` accepting key-value `Pair`s ([#23271]). +* `get` do-block syntax supported when using `ENV` ([#23412]). + ## Renaming @@ -366,6 +368,7 @@ includes this fix. Find the minimum version from there. [#23051]: https://github.com/JuliaLang/julia/issues/23051 [#23235]: https://github.com/JuliaLang/julia/issues/23235 [#23271]: https://github.com/JuliaLang/julia/issues/23271 +[#23412]: https://github.com/JuliaLang/julia/issues/23412 [#23427]: https://github.com/JuliaLang/julia/issues/23427 [#23570]: https://github.com/JuliaLang/julia/issues/23570 [#23666]: https://github.com/JuliaLang/julia/issues/23666 diff --git a/src/Compat.jl b/src/Compat.jl index a2b2684cd4bf2..4afa8dddbb4ee 100644 --- a/src/Compat.jl +++ b/src/Compat.jl @@ -853,6 +853,13 @@ end export Uninitialized, uninitialized end +# 0.7.0-DEV.1499 +if VERSION < v"0.7.0-DEV.1499" + function Base.get(f::Base.Callable, ::Base.EnvHash, k::AbstractString) + Base.access_env(k->f(), k) + end +end + include("deprecated.jl") end # module Compat diff --git a/test/runtests.jl b/test/runtests.jl index febea52cc16cc..d9447c17060e0 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -946,6 +946,12 @@ let A = [1] @test x == 1 end +# 0.7.0-DEV.1499 +let key = "TEST_23412" + @test !haskey(ENV, key) + @test get(() -> "default", ENV, key) == "default" +end + if VERSION < v"0.6.0" include("deprecated.jl") end