mauro3/Parameters.jl

Remove use of `show_default` internal?

Seelengrab opened this issue · 2 comments

:(function Base.show(io::IO, p::$tn)
if get(io, :compact, false) || get(io, :typeinfo, nothing)==$tn
Base.show_default(IOContext(io, :limit => true), p)
else
# just dumping seems to give ok output, in particular for big data-sets:
dump(IOContext(io, :limit => true), p, maxdepth=1)
end
end)

This seems dangerous, bypassing the whole show machinery. Not to mention, limit should already be set by default in the REPL if I'm not mistaken. This seems more appropriate, giving the same behavior but with the documented interface:

function Base.show(io::IO, ::MIME"text/plain", p::$tn) 
    if get(io, :compact, false) || get(io, :typeinfo, nothing)==$tn 
      show(IOContext(io, :limit => true), p)
    else
      # just dumping seems to give ok output, in particular for big data-sets:
      dump(IOContext(io, :limit => true), p, maxdepth=1) 
    end 
end

I'm not sure always passing :limit => true is a good idea, since that may have been set explicitly to false in the passed in IO.

mauro3 commented

I have to say that I don't know much about the show-internals, so it could well be that there can be improvements. Are you an expert?

So @kwdef changes the show behaviour, right?
For me, the different @show is kinda disturbing my workflow since I can't simply copy paste the printed object into the REPL such that it is valid Julia code again.

Is there a way to turn it off?

EDIT -> https://mauro3.github.io/Parameters.jl/dev/api/#Parameters.@with_kw_noshow-Tuple{Any}

julia> using Parameters

julia> struct Lel
           a
       end

julia> @with_kw struct Lel2
           a
       end
Lel2

julia> @show Lel(1.0)
Lel(1.0) = Lel(1.0)
Lel(1.0)

julia> @show Lel2(1.0)
Lel2(1.0) = Lel2
  a: Float64 1.0

Lel2
  a: Float64 1.0