-
-
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
Show Numbers compactly when typeinfo is a Union with Nothing or Missing #48822
Conversation
The function added here should be used in #45396 as well, creating a weak semantic merge conflict. |
This feels a little ad hoc and messy. How about checking if the type info intersected with |
Clever! |
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.
This doesn't seem correct since only unions with Nothing
or Missing
have the necessary convert
methods defined, so something like this will error:
julia> Union{String,Bool}[1]
ERROR: MethodError: Cannot `convert` an object of type
Int64 to an object of type
Union{Bool, String}
Closest candidates are:
convert(::Type{T}, ::T) where T at Base.jl:61
Stacktrace:
[1] setindex!(A::Vector{Union{Bool, String}}, x::Int64, i1::Int64)
@ Base ./array.jl:966
[2] getindex(#unused#::Type{Union{Bool, String}}, vals::Int64)
@ Base ./array.jl:407
[3] top-level scope
@ REPL[5]:1
This check probably needs to be something like typesubtract(get(io, :typeinfo, Any), Union{Nothing,Missing}) === Bool
instead
That function was deprecated a long time ago, but |
Seems like for my proposal julia> Base.typeintersect(Union{String,Bool}, Number)
Bool
julia> Base.typeintersect(Union{Int,Nothing,Missing}, Number)
Int64 |
IIUC, @StefanKarpinski want Alternatively, we could try to define convert(::Type{Union{T1, NonNumber}}, x::Number) where T1 <: Number = convert(T1, x) but this seems broken, fragile, and icky. The implementation using |
My new response to @StefanKarpinski's comment
is, we should special case |
Bump, I think that I have addressed all the comments. |
Bump |
@simeonschaub, I believe I have made your requested changes, can you confirm? |
Tagging triage to get a decision on this. Do we want this abbreviation? |
Triage says merge without the wider version and then reconsider wider version later if wanted |
Before:
After:
This is
repr
able because ofjulia/base/missing.jl
Line 70 in a23b29c
Fixes #39590
Fixes #26847
This cannot be extended to arbitrary types because sometimes that method is overwritten (e.g.
convert(Union{Nothing, Some{Int}}, 5)
fails)