Skip to content

fewer convert methods for Missing and Nothing#30205

Closed
JeffBezanson wants to merge 2 commits intomasterfrom
jb/convertmissingnothing
Closed

fewer convert methods for Missing and Nothing#30205
JeffBezanson wants to merge 2 commits intomasterfrom
jb/convertmissingnothing

Conversation

@JeffBezanson
Copy link
Copy Markdown
Member

@isdefined is a better approach than trying to add lots of methods to cover all cases. Some of the methods created bad cases for specificity. In particular defining conversions from Any (convert(::T, ::Any)) should be minimized since they tend to conflict with the fallback convert(::Type{T}, ::T).

@JeffBezanson JeffBezanson added types and dispatch Types, subtyping and method dispatch missing data Base.missing and related functionality labels Nov 30, 2018
Copy link
Copy Markdown
Member

@nalimilan nalimilan left a comment

Choose a reason for hiding this comment

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

Cool!

EDIT: except for the removal of some.jl, which seems to explain the CI failures. I thought I could trust you... :-)

@JeffBezanson
Copy link
Copy Markdown
Member Author

Somehow changing those methods causes sparse array broadcast to allocate...

@vtjnash
Copy link
Copy Markdown
Member

vtjnash commented Apr 3, 2019

I think we've been changing all of these to use typesubtract (e.g. #31016), and thereby making this a structural question instead of a subtyping question. With subtyping, it's unclear why the type-system should be expected to extract a particular value for T via intersection with Union{T, Nothing} where {T}, even though that result is non-unique (it should be either of T or T?), and therefore would normally not be expected to define a value for T.

That would also perhaps remove the Union from the signature and instead the expression of these rules would be something like (with a check that typesubtract returned a smaller type):

convert(T::Type{Any}, x) = x
convert(T::Type{Union{}}, x) = throw(MethodError(convert, (Union{}, x)))
convert(T::Type{>:Union{Missing, Nothing}}, x) = convert(typesubtract(typesubtract(T, Nothing), Missing), x)
convert(T::Type{>:Missing}, x) = convert(typesubtract(T, Missing), x)
convert(T::Type{>:Nothing}, x) = convert(typesubtract(T, Nothing), x)

@JeffBezanson
Copy link
Copy Markdown
Member Author

Replaced by #31602

@DilumAluthge DilumAluthge deleted the jb/convertmissingnothing branch March 25, 2021 21:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

missing data Base.missing and related functionality types and dispatch Types, subtyping and method dispatch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants