From e693c43c41e769e3363242125c36226affdebc3f Mon Sep 17 00:00:00 2001 From: hhaensel Date: Tue, 29 Oct 2024 18:12:15 +0100 Subject: [PATCH 1/4] better support for Unions with Nothing --- src/stipple/parsers.jl | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/stipple/parsers.jl b/src/stipple/parsers.jl index 4993ab48..ab623adb 100644 --- a/src/stipple/parsers.jl +++ b/src/stipple/parsers.jl @@ -15,6 +15,10 @@ function stipple_parse(::Type{T}, value) where T end end +function stipple_parse(::Type{T}, value::AbstractString) where T<:AbstractString + convert(T, value) +end + # function stipple_parse(::Type{T}, value::Dict) where T <: AbstractDict # convert(T, value) # end @@ -79,11 +83,16 @@ function stipple_parse(::Type{Union{Nothing, T}}, ::Nothing) where T nothing end -# Union with Nothing +# Union with Nothing, part I function stipple_parse(::Type{Union{Nothing, T}}, value) where T stipple_parse(T, value) end +# Union with Nothing, part II +function stipple_parse(::Type{Union{Nothing, T}}, value::Union{Nothing, T}) where T + stipple_parse(T, value) +end + # define an explicit function for Type{Any} to avoid ambiguities between Type{Union{Nothing, T}} and Type{T} (line 35 and line 64) in case of T == Any function stipple_parse(::Type{Any}, v::T) where {T} v::T From 165840f0f02e6121d69c3f9c148d0240a8f2894a Mon Sep 17 00:00:00 2001 From: hhaensel Date: Tue, 29 Oct 2024 18:18:45 +0100 Subject: [PATCH 2/4] add parsing tests for Union types --- test/runtests.jl | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/runtests.jl b/test/runtests.jl index 32393c5e..9aafac6e 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -594,4 +594,9 @@ end @test Stipple.stipple_parse(T2, t2_dict) == T2(1, T1(2, 3)) @test Stipple.stipple_parse(T3, Dict()) == T3(1, 3) @test Stipple.stipple_parse(T4, Dict()) == T4(1, T3(1, 3)) + + @test Stipple.stipple_parse(Union{Nothing, String}, "hi") == "hi" + @test Stipple.stipple_parse(Union{Nothing, String}, SubString("hi")) == "hi" + @test Stipple.stipple_parse(Union{Nothing, SubString}, "hi") == SubString("hi") + @test Stipple.stipple_parse(Union{Nothing, String}, nothing) === nothing end \ No newline at end of file From dde4d46f17ecb9e7cb69123379d4f5fd17800f0a Mon Sep 17 00:00:00 2001 From: hhaensel Date: Tue, 29 Oct 2024 18:18:50 +0100 Subject: [PATCH 3/4] set version v0.30.11 --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 1805f906..53acf600 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "Stipple" uuid = "4acbeb90-81a0-11ea-1966-bdaff8155998" authors = ["Adrian "] -version = "0.30.10" +version = "0.30.11" [deps] Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" From 5b924cca48d36ac7ccd5344456bd7e62d2be82c1 Mon Sep 17 00:00:00 2001 From: hhaensel Date: Tue, 29 Oct 2024 18:49:51 +0100 Subject: [PATCH 4/4] remove one failing test for version 1.6 --- test/runtests.jl | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/runtests.jl b/test/runtests.jl index 9aafac6e..dffaf611 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -597,6 +597,12 @@ end @test Stipple.stipple_parse(Union{Nothing, String}, "hi") == "hi" @test Stipple.stipple_parse(Union{Nothing, String}, SubString("hi")) == "hi" - @test Stipple.stipple_parse(Union{Nothing, SubString}, "hi") == SubString("hi") + # the following test is only valid for Julia 1.7 and above because specifity of methods + # changed in Julia 1.7. As the latest LTS version of Julia is now 1.10, we accept that + # this specific stipple_parse for Union{Nothing, T} fails for Julia 1.6 + # people can define explicit methods for their types if they need this functionality + @static if VERSION ≥ v"1.7" + @test Stipple.stipple_parse(Union{Nothing, SubString}, "hi") == SubString("hi") + end @test Stipple.stipple_parse(Union{Nothing, String}, nothing) === nothing end \ No newline at end of file