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

warning when redefining show, Julia >=0.5 only #20

Closed
stephancb opened this issue Nov 11, 2016 · 13 comments
Closed

warning when redefining show, Julia >=0.5 only #20

stephancb opened this issue Nov 11, 2016 · 13 comments
Labels

Comments

@stephancb
Copy link

Since Julia 0.5 I get (slightly annoying)

WARNING: Method definition show(IO, ....

when redefining the show function of a "with_kw" immutable:

julia> using Parameters

julia> @with_kw immutable Tstmp
           day2000::Int
           msec::Int
       end
Tstmp

julia> Base.show(io::IO, tt::Tstmp) = print(io, "days since 2000-01-01: $(tt.day2000) millisec of day: $(tt.msec)")
WARNING: Method definition show(IO, Main.Tstmp) in module Main at /home/scb/code/julia/pkg/v0.5/Parameters/src/Parameters.jl:375 overwritten at REPL[3]:1.
@mauro3
Copy link
Owner

mauro3 commented Nov 11, 2016

Yes, this is expected and is hitting one of 0.5's more controversial features:
JuliaLang/julia#18725

The @with_kw macro also defines a show method:

julia> type A
       a
       b
       end

julia> A(3,4)
A(3,4)

julia> @with_kw type B
       a
       b
       end
B

julia> B(3,4)
B
  a: 3
  b: 4

So if you define your own show method it will overwrite the one of @with_kw and trigger the warning.

Solutions: live with it or remove the show definition from the macro.

@stephancb
Copy link
Author

Ok, thanks.

@mauro3
Copy link
Owner

mauro3 commented Nov 11, 2016

One solution could be to have several macros, one of which, didn't make a show method. But that does lead to quite a bit more complexity, which I'm hesitant to add. I'll leave this open for now and ponder it some.

@mauro3
Copy link
Owner

mauro3 commented Nov 14, 2016

Also you could use https://github.com/Ismael-VC/Suppressor.jl:

julia> using Parameters

julia> @with_kw immutable Tstmp
           day2000::Int
           msec::Int
       end
Tstmp

julia> @suppress_err Base.show(io::IO, tt::Tstmp) = print(io, "days since 2000-01-01: $(tt.day2000) millisec of day: $(tt.msec)")

@mauro3
Copy link
Owner

mauro3 commented Feb 14, 2017

Closing this as "won't-fix" as I want to keep the automatically defined show methods.

@mauro3 mauro3 closed this as completed Feb 14, 2017
@mauro3 mauro3 added the wontfix label Feb 14, 2017
@juliohm
Copy link

juliohm commented Aug 20, 2017

Could you please reconsider this issue? I really like the keyword parameters, but I also think that in many cases the user wants to write their own Base.show. Using another package for just hiding the warning seems like hmmm... 👎

I hope the issue won't be ported to Base. Keyword parameters are awesome without shows.

@ChrisRackauckas
Copy link
Collaborator

@with_kw_noshow?

@juliohm
Copy link

juliohm commented Aug 20, 2017

Wonderful!

@mauro3
Copy link
Owner

mauro3 commented Aug 20, 2017

Ok.

@mauro3 mauro3 reopened this Aug 20, 2017
@mauro3 mauro3 closed this as completed in 03ced41 Aug 21, 2017
@mauro3 mauro3 reopened this Aug 21, 2017
@mauro3
Copy link
Owner

mauro3 commented Aug 21, 2017

This still needs docs, so I'll keep it open for now. But it works:

@with_kw_noshow struct A
a
end

@juliohm
Copy link

juliohm commented Aug 21, 2017

That is awesome @mauro3 , thanks for adding this feature 🙂

@mauro3
Copy link
Owner

mauro3 commented Aug 21, 2017

You're welcome!

@mauro3
Copy link
Owner

mauro3 commented Aug 23, 2017

Now also has docs.

@mauro3 mauro3 closed this as completed Aug 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants