Skip to content

Commit

Permalink
fix IOContext(::IO) (fix JuliaLang#25638) (JuliaLang#25649)
Browse files Browse the repository at this point in the history
  • Loading branch information
rfourquet authored and JeffBezanson committed Jan 20, 2018
1 parent 67ee6c6 commit 0275ce6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
9 changes: 7 additions & 2 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -598,9 +598,14 @@ end
@deprecate_binding golden MathConstants.golden

# PR #23271
# TODO: rename Base._IOContext to IOContext when this deprecation is deleted
function IOContext(io::IO; kws...)
depwarn("`IOContext(io, k=v, ...)` is deprecated, use `IOContext(io, :k => v, ...)` instead.", :IOContext)
IOContext(io, (k=>v for (k, v) in pairs(kws))...)
if isempty(kws) # Issue #25638
_IOContext(io)
else
depwarn("`IOContext(io, k=v, ...)` is deprecated, use `IOContext(io, :k => v, ...)` instead.", :IOContext)
IOContext(io, (k=>v for (k, v) in pairs(kws))...)
end
end

@deprecate IOContext(io::IO, key, value) IOContext(io, key=>value)
Expand Down
3 changes: 3 additions & 0 deletions base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ end

convert(::Type{IOContext}, io::IO) = IOContext(unwrapcontext(io)...)

# rename to IOContext when deprecation of `IOContext(io::IO; kws...)` is removed
_IOContext(io::IO) = convert(IOContext, io)

function IOContext(io::IO, KV::Pair)
io0, d = unwrapcontext(io)
IOContext(io0, ImmutableDict{Symbol,Any}(d, KV[1], KV[2]))
Expand Down
13 changes: 13 additions & 0 deletions test/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@ include("testenv.jl")
replstr(x) = sprint((io,x) -> show(IOContext(io, :limit => true, :displaysize => (24, 80)), MIME("text/plain"), x), x)
showstr(x) = sprint((io,x) -> show(IOContext(io, :limit => true, :displaysize => (24, 80)), x), x)

@testset "IOContext" begin
io = IOBuffer()
ioc = IOContext(io)
@test ioc.io == io
@test ioc.dict == Base.ImmutableDict{Symbol, Any}()
ioc = IOContext(io, :x => 1)
@test ioc.io == io
@test ioc.dict == Base.ImmutableDict{Symbol, Any}(:x, 1)
ioc = IOContext(io, :x => 1, :y => 2)
@test ioc.io == io
@test ioc.dict == Base.ImmutableDict(Base.ImmutableDict{Symbol, Any}(:x, 1),
:y => 2)
end

@test replstr(Array{Any}(uninitialized, 2)) == "2-element Array{Any,1}:\n #undef\n #undef"
@test replstr(Array{Any}(uninitialized, 2,2)) == "2×2 Array{Any,2}:\n #undef #undef\n #undef #undef"
Expand Down

0 comments on commit 0275ce6

Please sign in to comment.