Skip to content

Commit c418a10

Browse files
repr: allow context pairs when calling show
use this instead of the special-case `Base.reprfull` in loading
1 parent 808e828 commit c418a10

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

base/loading.jl

+1-7
Original file line numberDiff line numberDiff line change
@@ -1047,12 +1047,6 @@ function evalfile(path::AbstractString, args::Vector{String}=String[])
10471047
end
10481048
evalfile(path::AbstractString, args::Vector) = evalfile(path, String[args...])
10491049

1050-
function reprfull(x)
1051-
s = IOBuffer()
1052-
show(IOContext(s, :module => nothing), x)
1053-
String(take!(s))
1054-
end
1055-
10561050
function create_expr_cache(input::String, output::String, concrete_deps::typeof(_concrete_dependencies), uuid::Union{Nothing,UUID})
10571051
rm(output, force=true) # Remove file if it exists
10581052
code_object = """
@@ -1072,7 +1066,7 @@ function create_expr_cache(input::String, output::String, concrete_deps::typeof(
10721066
write(in, """
10731067
begin
10741068
empty!(Base.LOAD_PATH)
1075-
append!(Base.LOAD_PATH, $(reprfull(LOAD_PATH)))
1069+
append!(Base.LOAD_PATH, $(repr(LOAD_PATH, :module => nothing)))
10761070
empty!(Base.DEPOT_PATH)
10771071
append!(Base.DEPOT_PATH, $(repr(DEPOT_PATH)))
10781072
empty!(Base.LOAD_CACHE_PATH)

base/strings/io.jl

+9
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,11 @@ end
151151

152152
"""
153153
repr(x)
154+
repr(x, context::Pair{Symbol,<:Any}...)
154155
155156
Create a string from any value using the [`show`](@ref) function.
157+
If context pairs are given, the IO buffer used to capture `show` output
158+
is wrapped in an `IOContext` object with those context pairs.
156159
157160
# Examples
158161
```jldoctest
@@ -170,6 +173,12 @@ function repr(x)
170173
String(take!(s))
171174
end
172175

176+
function repr(x, context::Pair{Symbol}...)
177+
s = IOBuffer()
178+
show(IOContext(s, context...), x)
179+
String(take!(s))
180+
end
181+
173182
# IOBuffer views of a (byte)string:
174183

175184
"""

0 commit comments

Comments
 (0)