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

fix some cases of typeinfo printing #33290

Merged
merged 2 commits into from
Sep 18, 2019
Merged

fix some cases of typeinfo printing #33290

merged 2 commits into from
Sep 18, 2019

Conversation

JeffBezanson
Copy link
Member

@JeffBezanson JeffBezanson commented Sep 17, 2019

Fixes #30683

Before:

julia> show(Dict(true=>false))
Dict(1 => 0)

after:

julia> show(Dict(true=>false))
Dict{Bool,Bool}(1 => 0)

Also fixes other similar cases with Dict, e.g.

julia> show(Dict(Any[1]=>Any[2]))
Dict([1] => [2])

As a bonus, there are also some reductions in verbosity. Certain types never need type info, e.g. [1] can always be shown instead of Int[1]. This adds Symbol and singleton types to that set.

@JeffBezanson JeffBezanson added the display and printing Aesthetics and correctness of printed representations of objects. label Sep 17, 2019
@rfourquet
Copy link
Member

rfourquet commented Sep 17, 2019

EDIT: fixed it.
The one error I see from the tests is:

Test Failed at /buildworker/worker/tester_linux64/build/share/julia/test/missing.jl:224
  Expression: sprint(show, [missing]) == "$(Missing)[missing]"
   Evaluated: "[missing]" == "Missing[missing]"

@rfourquet
Copy link
Member

This looks like an improvement in general, and the isconcretetype test was not a great heuristic, but there are cases where this change looks unnecessarily more verbose:

julia> show(Dict((1=>2) => (3=>4)))
Dict{Pair{Int64,Int64},Pair{Int64,Int64}}((1 => 2) => (3 => 4))

(Before: Dict((1 => 2) => (3 => 4)))

@@ -457,6 +457,11 @@ typeinfo_eltype(typeinfo::Type{<:AbstractArray{T}}) where {T} = eltype(typeinfo)
typeinfo_eltype(typeinfo::Type{<:AbstractDict{K,V}}) where {K,V} = eltype(typeinfo)
typeinfo_eltype(typeinfo::Type{<:AbstractSet{T}}) where {T} = eltype(typeinfo)

# types that can be parsed back accurately from their un-decorated representations
function typeinfo_implicit(@nospecialize(T))
return T === Float64 || T === Int || T === Char || T === String || T === Symbol ||
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it for compiler friendlyness that you don't write something like T in (Float64, Int, Char, String, Symbol) ?

@JeffBezanson
Copy link
Member Author

Dict{Pair{Int64,Int64},Pair{Int64,Int64}}((1 => 2) => (3 => 4))

I think we could make typeinfo_implicit recursive through Dict, Array, Pair, and Tuple element types.

test/core.jl Outdated Show resolved Hide resolved
@JeffBezanson
Copy link
Member Author

Ok, now everything looks real nice. We can remove a bunch more redundant type info too.

Copy link
Member

@rfourquet rfourquet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's great!

@JeffBezanson JeffBezanson merged commit 9c6d749 into master Sep 18, 2019
@delete-merged-branch delete-merged-branch bot deleted the jb/showdictbool branch September 18, 2019 17:15
timholy added a commit to timholy/Revise.jl that referenced this pull request Sep 20, 2019
This fixes a test failure on nightly, ref 
JuliaLang/julia#33290.
timholy added a commit to timholy/Revise.jl that referenced this pull request Sep 20, 2019
This fixes a test failure on nightly, ref 
JuliaLang/julia#33290.
@maleadt maleadt mentioned this pull request Jan 15, 2020
28 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
display and printing Aesthetics and correctness of printed representations of objects.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0/1 printing of false/true is confusing in Dict
2 participants