Skip to content

Commit 2a9f33c

Browse files
authored
add print_signature_only argument to Base.show_method (JuliaLang#58647)
1 parent 995ea2c commit 2a9f33c

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

base/methodshow.jl

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,9 @@ show(io::IO, m::Method; kwargs...) = show_method(IOContext(io, :compact=>true),
214214

215215
show(io::IO, ::MIME"text/plain", m::Method; kwargs...) = show_method(io, m; kwargs...)
216216

217-
function show_method(io::IO, m::Method; modulecolor = :light_black, digit_align_width = 1)
217+
function show_method(io::IO, m::Method;
218+
modulecolor = :light_black, digit_align_width = 1,
219+
print_signature_only::Bool = get(io, :print_method_signature_only, false)::Bool)
218220
tv, decls, file, line = arg_decl_parts(m)
219221
sig = unwrap_unionall(m.sig)
220222
if sig === Tuple
@@ -250,12 +252,14 @@ function show_method(io::IO, m::Method; modulecolor = :light_black, digit_align_
250252
show_method_params(io, tv)
251253
end
252254

253-
if !(get(io, :compact, false)::Bool) # single-line mode
254-
println(io)
255-
digit_align_width += 4
255+
if !print_signature_only
256+
if !(get(io, :compact, false)::Bool) # single-line mode
257+
println(io)
258+
digit_align_width += 4
259+
end
260+
# module & file, re-using function from errorshow.jl
261+
print_module_path_file(io, parentmodule(m), string(file), line; modulecolor, digit_align_width)
256262
end
257-
# module & file, re-using function from errorshow.jl
258-
print_module_path_file(io, parentmodule(m), string(file), line; modulecolor, digit_align_width)
259263
end
260264

261265
function show_method_list_header(io::IO, ms::MethodList, namefmt::Function)

test/show.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2885,3 +2885,15 @@ end
28852885
@test_repr """:(var"\a\b\t\n\v\f\r\e" = 1)"""
28862886
@test_repr """:(var"\x01\u03c0\U03c0" = 1)"""
28872887
end
2888+
2889+
# test `print_signature_only::Bool` argument of `Base.show_method`
2890+
f_show_method(x::T) where T<:Integer = :integer
2891+
let m = only(methods(f_show_method))
2892+
let io = IOBuffer()
2893+
Base.show_method(io, m; print_signature_only=true)
2894+
@test "f_show_method(x::T) where T<:Integer" == String(take!(io))
2895+
end
2896+
let s = sprint(show, m; context=:print_method_signature_only=>true)
2897+
@test "f_show_method(x::T) where T<:Integer" == s
2898+
end
2899+
end

0 commit comments

Comments
 (0)