Skip to content
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

Remove use of show_default internal? #151

Open
Seelengrab opened this issue Feb 22, 2023 · 2 comments
Open

Remove use of show_default internal? #151

Seelengrab opened this issue Feb 22, 2023 · 2 comments

Comments

@Seelengrab
Copy link

:(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
Copy link
Owner

mauro3 commented Apr 30, 2023

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
Copy link

roflmaostc commented Sep 12, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants