-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
methodshow: single-line printing for Method
by default
#46241
Conversation
Does this impact printing of e.g. |
No, those printings won't be affected by this PR> |
Currently `show(::IO, ::Method)` prints the method object in multiple-line as like: ```julia julia> only(methods(sin, (Float64,))) sin(x::T) where T<:Union{Float32, Float64} @ Base.Math special/trig.jl:29 ``` and this could be confusing when used within a container e.g.: ```julia julia> Any[only(methods(sin, (Float64,)))] 1-element Vector{Any}: sin(x::T) where T<:Union{Float32, Float64} @ Base.Math special/trig.jl:29 julia> code_lowered() do; Base.Experimental.@opaque a::Int -> sin(a); end 1-element Vector{Core.CodeInfo}: CodeInfo( 1 ─ %1 = Core.apply_type(Core.Tuple, Main.Int) │ %2 = Core.apply_type(Core.Union) │ %3 = $(Expr(:new_opaque_closure, :(%1), :(%2), :(Core.Any), opaque closure(...) @ Main none:0)) └── return %3 ) ``` This commit refactors the `show` method for `Method` object so that `show(::IO, ::Method)` prints it within a single line by default and `show(::IO, ::MIME"text/plain", ::Method)` prints within 2-lines, that I believe is more aligned with printing implementations for the other types: ```julia julia> Any[only(methods(sin, (Float64,)))] 1-element Vector{Any}: sin(x::T) where T<:Union{Float32, Float64} @ Base.Math special/trig.jl:29 julia> code_lowered() do; Base.Experimental.@opaque a::Int -> sin(a); end 1-element Vector{Core.CodeInfo}: CodeInfo( 1 ─ %1 = Core.apply_type(Core.Tuple, Main.Int) │ %2 = Core.apply_type(Core.Union) │ %3 = $(Expr(:new_opaque_closure, :(%1), :(%2), :(Core.Any), opaque closure(...) @ Main none:0)) └── return %3 ) ```
ed84454
to
3f33e68
Compare
CI looks fine. Are there any objections? Otherwise I'd merge this soonish. |
Yeah, looks good to me! Thank you as well for cleaning up the indentation numbers being passed around :) |
…6241) Currently `show(::IO, ::Method)` prints the method object in multiple-line as like: ```julia julia> only(methods(sin, (Float64,))) sin(x::T) where T<:Union{Float32, Float64} @ Base.Math special/trig.jl:29 ``` and this could be confusing when used within a container e.g.: ```julia julia> Any[only(methods(sin, (Float64,)))] 1-element Vector{Any}: sin(x::T) where T<:Union{Float32, Float64} @ Base.Math special/trig.jl:29 julia> code_lowered() do; Base.Experimental.@opaque a::Int -> sin(a); end 1-element Vector{Core.CodeInfo}: CodeInfo( 1 ─ %1 = Core.apply_type(Core.Tuple, Main.Int) │ %2 = Core.apply_type(Core.Union) │ %3 = $(Expr(:new_opaque_closure, :(%1), :(%2), :(Core.Any), opaque closure(...) @ Main none:0)) └── return %3 ) ``` This commit refactors the `show` method for `Method` object so that `show(::IO, ::Method)` prints it within a single line by default and `show(::IO, ::MIME"text/plain", ::Method)` prints within 2-lines, that I believe is more aligned with printing implementations for the other types: ```julia julia> Any[only(methods(sin, (Float64,)))] 1-element Vector{Any}: sin(x::T) where T<:Union{Float32, Float64} @ Base.Math special/trig.jl:29 julia> code_lowered() do; Base.Experimental.@opaque a::Int -> sin(a); end 1-element Vector{Core.CodeInfo}: CodeInfo( 1 ─ %1 = Core.apply_type(Core.Tuple, Main.Int) │ %2 = Core.apply_type(Core.Union) │ %3 = $(Expr(:new_opaque_closure, :(%1), :(%2), :(Core.Any), opaque closure(...) @ Main none:0)) └── return %3 ) ```
…6241) Currently `show(::IO, ::Method)` prints the method object in multiple-line as like: ```julia julia> only(methods(sin, (Float64,))) sin(x::T) where T<:Union{Float32, Float64} @ Base.Math special/trig.jl:29 ``` and this could be confusing when used within a container e.g.: ```julia julia> Any[only(methods(sin, (Float64,)))] 1-element Vector{Any}: sin(x::T) where T<:Union{Float32, Float64} @ Base.Math special/trig.jl:29 julia> code_lowered() do; Base.Experimental.@opaque a::Int -> sin(a); end 1-element Vector{Core.CodeInfo}: CodeInfo( 1 ─ %1 = Core.apply_type(Core.Tuple, Main.Int) │ %2 = Core.apply_type(Core.Union) │ %3 = $(Expr(:new_opaque_closure, :(%1), :(%2), :(Core.Any), opaque closure(...) @ Main none:0)) └── return %3 ) ``` This commit refactors the `show` method for `Method` object so that `show(::IO, ::Method)` prints it within a single line by default and `show(::IO, ::MIME"text/plain", ::Method)` prints within 2-lines, that I believe is more aligned with printing implementations for the other types: ```julia julia> Any[only(methods(sin, (Float64,)))] 1-element Vector{Any}: sin(x::T) where T<:Union{Float32, Float64} @ Base.Math special/trig.jl:29 julia> code_lowered() do; Base.Experimental.@opaque a::Int -> sin(a); end 1-element Vector{Core.CodeInfo}: CodeInfo( 1 ─ %1 = Core.apply_type(Core.Tuple, Main.Int) │ %2 = Core.apply_type(Core.Union) │ %3 = $(Expr(:new_opaque_closure, :(%1), :(%2), :(Core.Any), opaque closure(...) @ Main none:0)) └── return %3 ) ```
Currently
show(::IO, ::Method)
prints the method object inmultiple-line as like:
and this could be confusing when used within a container e.g.:
This commit refactors the
show
method forMethod
object so thatshow(::IO, ::Method)
prints it within a single line by default andshow(::IO, ::MIME"text/plain", ::Method)
prints within 2-lines,that I believe is more aligned with printing implementations for
the other types:
/cc @Seelengrab