diff --git a/base/show.jl b/base/show.jl index 879916d794f96..14373604fe6f5 100644 --- a/base/show.jl +++ b/base/show.jl @@ -3222,17 +3222,23 @@ end summary(io::IO, f::Function) = show(io, MIME"text/plain"(), f) """ - showarg(io::IO, x, toplevel) + Base.showarg(io::IO, x, toplevel) -Show `x` as if it were an argument to a function. This function is -used by [`summary`](@ref) to display type information in terms of sequences of -function calls on objects. `toplevel` is `true` if this is -the direct call from `summary` and `false` for nested (recursive) calls. +Show the quasi-type of `x` where quasi-type is the type of `x` or an expression (possibly +containing quasi-types) that would generate an object of the same type as `x`. The shorter +of these two options is typically used. -The fallback definition is to print `x` as "::\\\$(typeof(x))", -representing argument `x` in terms of its type. (The double-colon is -omitted if `toplevel=true`.) However, you can -specialize this function for specific types to customize printing. +This function is used by summary to display type information in terms of sequences of +function calls on objects. + +Show a leading `::` if `toplevel` is `false` and showing a type. `toplevel` is `true` if +this is the direct call from `summary` and `false` for nested (recursive) calls. + +The fallback definition is to print x as "::$(typeof(x))", representing argument x in terms +of its type. (The double-colon is omitted if toplevel=true.) However, you can specialize +this function for specific types to customize printing. This customization is useful for +types that have simple constructors and verbose types such as `reinterpret`ed arrays or +`SubArray`s. # Examples @@ -3261,14 +3267,14 @@ type, indicating that any recursed calls are not at the top level. Printing the parent as `::Array{Float64,3}` is the fallback (non-toplevel) behavior, because no specialized method for `Array` has been defined. """ -function showarg(io::IO, T::Type, toplevel) - toplevel || print(io, "::") - print(io, "Type{", T, "}") -end function showarg(io::IO, @nospecialize(x), toplevel) toplevel || print(io, "::") print(io, typeof(x)) end +function showarg(io::IO, T::Type, toplevel) + toplevel || print(io, "::") + print(io, "Type{", T, "}") +end # This method resolves an ambiguity for packages that specialize on eltype function showarg(io::IO, a::Array{Union{}}, toplevel) toplevel || print(io, "::")