Skip to content

Update showarg docstring #58509

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 19 additions & 13 deletions base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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`, whichever is
shorter.

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

Expand Down Expand Up @@ -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, "::")
Expand Down