-
-
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: Throw an error when coalesce is passed only nothing/missing arguments #27157
Conversation
base/some.jl
Outdated
for T in (:Nothing, :Missing) | ||
@eval begin | ||
coalesce(x::$T, y::Union{Nothing, Missing}) = | ||
throw(ArgumentError("coalesce requires that least one argument differs from `nothing` or `missing`; " * |
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.
The line here is pretty long. I'd suggest changing the semicolon to a period and the space after it to a newline. Not a big deal though.
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.
Fast! I wasn't sure what's the convention about this. It's indeed problematic in the doctest.
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.
Fixed.
Remove the one-argument method, which does not allow passing a replacement value which can never be nothing/missing. The old behavior can still be obtained by passing Some(nothing)/Some(missing) as last argument. Also add a tests for recursively wrapped values like Some(Some(1)), and remove useless 'using Base: coalesce' statements (from the time when it was not exported).
Used in one place in Base, and it's the only way of unwrapping Some.
If this PR is merged I would recommend to update documentation of |
I think this is going in the right direction, but it seems really weird to me that |
Remove the one-argument method, which does not allow passing a replacement value which can never be nothing/missing. The old behavior can still be obtained by passing
Some(nothing)
/Some(missing)
as last argument.Possible fix for #26927.
The advantage of this PR is that it implements a strict subset of the previous behavior. So if we change our minds and decide to allow returning
nothing
/missing
when all arguments arenothing
/missing
(as in SQL and dplyr), it won't break anything.EDIT: instead of throwing an error, we could first print a deprecation.
EDIT2: the last commit also implements the proposal made by @Keno at #26927, i.e. when
nothing
andmissing
are mixed only the first one is replaced, and the other is considered as non missing and therefore returned as-is.