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

Don't overload show(io, ::Type) #31

Closed
ararslan opened this issue May 15, 2018 · 9 comments
Closed

Don't overload show(io, ::Type) #31

ararslan opened this issue May 15, 2018 · 9 comments

Comments

@ararslan
Copy link
Contributor

This is type treason, as Jeff puts it, and makes Bad Things Happen on 0.7. See JuliaLang/julia#24195. If we simply do away with those methods, the printing is a little less concise, but still reasonable (IMO):

julia> HourBeginning
AnchoredInterval{1 hour,T} where T<:Dates.TimeType

This is in line with how Base prints aliases, e.g.

julia> AbstractVecOrMat
Union{AbstractArray{T,1}, AbstractArray{T,2}} where T

Thoughts?

@rofinn
Copy link
Member

rofinn commented May 15, 2018

I'd be fine with that change. This should also be a little simpler once we merge #12.

@iamed2
Copy link
Member

iamed2 commented May 15, 2018

Is it possible to override only how they're shown in the REPL? Could we override just
show(::IO, ::MIME"text/plain", ::Type{T}) where T <: ...

@iamed2
Copy link
Member

iamed2 commented May 15, 2018

Or display?

@ararslan
Copy link
Contributor Author

Either way we're still committing type piracy though.

@iamed2
Copy link
Member

iamed2 commented May 15, 2018

Are we? Is base_method(::BaseType{MyType}) type piracy?

@ararslan
Copy link
Contributor Author

Yes, that's why changing show(::IO, ::Type{T}) for any T is problematic, as Jeff noted in the linked issue.

@iamed2
Copy link
Member

iamed2 commented May 16, 2018

It sounds like we have to do this, so let's add showarg methods at the same time to mitigate the downside.

@ararslan
Copy link
Contributor Author

Closed by #30.

@vtjnash
Copy link

vtjnash commented Aug 26, 2021

JuliaLang triage asked why the example needed to be a type, rather than a singleton value? (and hopefully the type-alias-based printing in base now helps this case, assuming HourBeginning is exported!)

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

4 participants