From a0fc1bf5ecd07dc27ccde221e983d9af87859f8b Mon Sep 17 00:00:00 2001 From: Stephan Sahm Date: Sun, 21 Jul 2024 12:07:45 +0200 Subject: [PATCH] support fallback concrete types for abstract number types --- Project.toml | 2 +- src/ConfigurationsENV.jl | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index 3890c1f..83aebec 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "ConfigurationsENV" uuid = "4a543033-a920-4921-b9ec-d69f25e1cf2a" authors = ["Stephan Sahm and contributors"] -version = "0.1.0" +version = "0.1.1" [deps] Configurations = "5218b696-f38b-4ac9-8b61-a12ec717816d" diff --git a/src/ConfigurationsENV.jl b/src/ConfigurationsENV.jl index f876b28..6e3642a 100644 --- a/src/ConfigurationsENV.jl +++ b/src/ConfigurationsENV.jl @@ -21,7 +21,10 @@ function from_string(u::Union, str) end end from_string(::Type{String}, str) = string(str) -from_string(::Type{T}, str) where {T<:Number} = parse(T, str) +_defaulttype(::Type{<:Complex}) = Complex{Float64} +_defaulttype(::Type{<:Real}) = Float64 +_defaulttype(::Type{<:Integer}) = Int +from_string(::Type{T}, str) where {T<:Number} = isconcretetype(T) ? parse(T, str) : parse(_defaulttype(T), str) from_string(::Type{T}, str) where {T} = T(str) @cont function nestedkeys_and_types(::Type{T}) where {T}