From 6d19ea9ca46312dfcf63fc2926959026578228f8 Mon Sep 17 00:00:00 2001 From: Jeff Date: Fri, 18 Sep 2020 00:22:05 -0700 Subject: [PATCH] parse and tryparse handling Nothing and Missing This allows parse and tryparse to allow Nothing and Missing types as inputs, returning the original input. --- base/parse.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/base/parse.jl b/base/parse.jl index 1097e8a19b804..cc4cbc214bb62 100644 --- a/base/parse.jl +++ b/base/parse.jl @@ -380,6 +380,8 @@ parse(::Type{T}, s::AbstractString; kwargs...) where T<:Real = convert(T, tryparse_internal(T, s, true; kwargs...)) parse(::Type{T}, s::AbstractString) where T<:Complex = convert(T, tryparse_internal(T, s, firstindex(s), lastindex(s), true)) +parse(::Type{T}, s::Union{Missing, Nothing}) where T<:Number = s tryparse(T::Type{Complex{S}}, s::AbstractString) where S<:Real = tryparse_internal(T, s, firstindex(s), lastindex(s), false) +tryparse(::Type{T}, s::Union{Missing, Nothing}) where T<:Number = s