-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
RFC: print Array{T,1} as Vector{T} and Array{T,2} as Matrix{T} #36032
Conversation
a75ccf4
to
68bc5b3
Compare
68bc5b3
to
eb9c912
Compare
Statistics fail the doctests. @nalimilan, I'm not sure it is feasible to have Statistics live outside this repo but still run the CI / doctests for it. Too much friction. |
Can this be generalized to user-defined types? How about @typealias MyVector{T} = MyArray{T,1} for writing |
Yes, I guess we can point people to (a stable variant of) https://julialang.github.io/Statistics.jl/dev/ instead. |
The pedagogical reservation is something I struggled with in #31149, too. To help alleviate it, I made sure the docs for |
@@ -588,12 +588,16 @@ end | |||
|
|||
function show_datatype(io::IO, x::DataType) | |||
istuple = x.name === Tuple.name | |||
isarray = x.name === Array{TypeVar(:T), TypeVar(:N)}.name |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isarray = x.name === Array{TypeVar(:T), TypeVar(:N)}.name | |
isarray = x.name === Array.body.body.name |
Triage was pretty much in favor — the two reservations were:
If we're going to break the doctests, it may be worth doing a more comprehensive solution all at once — searching the type's module for (potentially exported) names that define aliases and printing out the most specific ones. @vtjnash will try generalizing it in this manner, which will make it more useful and provide a bit more of a reward to packages. |
Perhaps an IOContext parameter that disables this? |
Would |
Can we have something like """
show_typealias(io::IO, T::Type)
Try printing type alias for `T`.
"""
show_typealias(::IO, ::Type) = nothing
function show(io::IO, @nospecialize(x::Type))
if get(io, :typealias, true)
alias = try
sprint(show_typealias; context = io)
catch err
msg = sprint(context = IOContext(io, :typealias => false)) do buf
println(buf, "ERROR: show_typealias(::IO, ::")
show_type(buf, x)
println(buf, ") failed")
showerror(buf, err)
end
println(stderr, msg)
()
end
if !isempty(alias)
print(io, alias)
return
end
end
show_type(io, x)
end
function show_type(io::IO, @nospecialize(x::Type))
# current show(::IO, ::Type) implementation
end ? (It can be made safer and more efficient but I think it's enough for a sketch.) |
I think we should merge this since (1) everyone seems to agree on this subset of changes, (2) we might as well get all those test and doc updates in. |
The annoying part is that this breaks doctest for Statistics which is not in this repo :/ Not sure how to deal with it. Turn off the doctests for Statistics? |
cc @nalimilan |
Yeah I already commented above. If that's possible, turning off doctests for Statistics should be OK since we run them in Statistics.jl anyway. Otherwise the section the manual could point to https://julialang.github.io/Statistics.jl/dev/. |
Yeah, I have the same problem over at #36107. I made the necessary changes locally just for testing. We could push those upstream, then merge this with the new commit hash. Or figure out how to stop running them. I'm inclined towards the former?
Pros: we think this subset is good, and it'd directly reduce the diff of future possible changes. Cons: if we're going to break a lot of doctests (with this, and then again with (#361007), might be worth doing it all at once, and not twice. |
Personally I find this clearer, especially when types are nested.
As an example
vs
Some potential objections:
AbstractVector
,DenseVector
etc? Could also be special cased imo.Vector{T}
is just another name forArray{T, 1}
. - I feel this is something you learn pretty quickly and the convenience in printing makes up for the slight "pedagogical" issue.