mauro3 / Parameters.jl

Types with default field values, keyword constructors and (un-)pack macros
Other
420 stars 31 forks source link

Remove use of `show_default` internal? #151

Open Seelengrab opened 1 year ago

Seelengrab commented 1 year ago

https://github.com/mauro3/Parameters.jl/blob/e55b025b96275142ba52b2a725aedf460f26ff6f/src/Parameters.jl#L581-L588

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 1 year ago

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?

roflmaostc commented 1 year ago

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