diff --git a/Project.toml b/Project.toml index a4ec7d22..3281a3ae 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "DrWatson" uuid = "634d3b9d-ee7a-5ddf-bec9-22491ea816e1" repo = "https://github.com/JuliaDynamics/DrWatson.jl.git" -version = "2.4.1" +version = "2.4.2" [deps] Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" diff --git a/src/naming.jl b/src/naming.jl index 4e4f3141..3a41e600 100644 --- a/src/naming.jl +++ b/src/naming.jl @@ -346,10 +346,11 @@ end # Credit of `ntuple` macro goes to Sebastian Pfitzner, @pfitzseb """ - ntuple2dict(nt) -> dict + ntuple2dict([type = Dict,] nt) -> dict Convert a `NamedTuple` to a dictionary. """ -ntuple2dict(nt::NamedTuple) = Dict(k => nt[k] for k in keys(nt)) +ntuple2dict(::Type{DT},nt::NamedTuple) where {DT<:AbstractDict} = DT(k => nt[k] for k in keys(nt)) +ntuple2dict(nt::NamedTuple) = ntuple2dict(Dict,nt) """ dict2ntuple(dict) -> ntuple diff --git a/test/stools_tests.jl b/test/stools_tests.jl index cd936813..d6bc68f6 100644 --- a/test/stools_tests.jl +++ b/test/stools_tests.jl @@ -313,6 +313,12 @@ rm(tmpdir, force = true, recursive = true) d11 = tosymboldict(OrderedDict,d10) @test isa(d11,OrderedDict) + #test ntuple2dict + x = 3; y = 5.0; + n = @ntuple x y + @test isa(ntuple2dict(n),Dict) + @test isa(ntuple2dict(OrderedDict,n),OrderedDict) + #test checktagtype! @test isa(DrWatson.checktagtype!(d3),Dict) @test isa(DrWatson.checktagtype!(d11),OrderedDict)