From 991e92d1dbdd7810febcc6e391a5a5a2c7a01aa6 Mon Sep 17 00:00:00 2001 From: Alexander Plavin Date: Mon, 26 Aug 2024 05:56:57 -0400 Subject: [PATCH] set(): relax NTuple type constraints (#165) * set(endpoints): relax type signature * set(dates): relax type signature --- ext/AccessorsDatesExt.jl | 6 +++--- ext/AccessorsIntervalSetsExt.jl | 2 +- test/test_extensions.jl | 1 + test/test_functionlenses.jl | 6 +++--- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/ext/AccessorsDatesExt.jl b/ext/AccessorsDatesExt.jl index 392f5276..9f9787c6 100644 --- a/ext/AccessorsDatesExt.jl +++ b/ext/AccessorsDatesExt.jl @@ -16,9 +16,9 @@ set(x::Time, ::typeof(Dates.value), y) = @set x.instant.value = y set(x::Date, ::typeof(year), y) = Date(y, month(x), day(x)) set(x::Date, ::typeof(month), y) = Date(year(x), y, day(x)) set(x::Date, ::typeof(day), y) = Date(year(x), month(x), y) -set(x::Date, ::typeof(yearmonth), y::NTuple{2}) = Date(y..., day(x)) -set(x::Date, ::typeof(monthday), y::NTuple{2}) = Date(year(x), y...) -set(x::Date, ::typeof(yearmonthday), y::NTuple{3}) = Date(y...) +set(x::Date, ::typeof(yearmonth), y::NTuple{2, Any}) = Date(y..., day(x)) +set(x::Date, ::typeof(monthday), y::NTuple{2, Any}) = Date(year(x), y...) +set(x::Date, ::typeof(yearmonthday), y::NTuple{3, Any}) = Date(y...) set(x::Date, ::typeof(dayofweek), y) = firstdayofweek(x) + Day(y - 1) set(x::Time, ::typeof(hour), y) = Time(y, minute(x), second(x), millisecond(x), microsecond(x), nanosecond(x)) diff --git a/ext/AccessorsIntervalSetsExt.jl b/ext/AccessorsIntervalSetsExt.jl index 11ccd0e4..b4b7ec30 100644 --- a/ext/AccessorsIntervalSetsExt.jl +++ b/ext/AccessorsIntervalSetsExt.jl @@ -2,7 +2,7 @@ module AccessorsIntervalSetsExt using Accessors using IntervalSets -Accessors.set(x::Interval, ::typeof(endpoints), v::NTuple{2}) = setproperties(x, left=first(v), right=last(v)) +Accessors.set(x::Interval, ::typeof(endpoints), v::NTuple{2, Any}) = setproperties(x, left=first(v), right=last(v)) Accessors.set(x::Interval, ::typeof(leftendpoint), v) = @set x.left = v Accessors.set(x::Interval, ::typeof(rightendpoint), v) = @set x.right = v Accessors.set(x::Interval, ::typeof(closedendpoints), v::NTuple{2, Bool}) = Interval{v[1] ? :closed : :open, v[2] ? :closed : :open}(endpoints(x)...) diff --git a/test/test_extensions.jl b/test/test_extensions.jl index 0c23cb3f..9361f9dd 100644 --- a/test/test_extensions.jl +++ b/test/test_extensions.jl @@ -53,6 +53,7 @@ VERSION >= v"1.9-" && @testset "IntervalSets" begin @test Interval{:open, :closed}(1, 10) === @set int.right = 10 @test Interval{:open, :closed}(10.0, 11.0) === @set endpoints(int) = (10.0, 11.0) + @test Interval{:open, :closed}(10.0, 11.0) === @set endpoints(int) = (10, 11.0) @test Interval{:open, :closed}(-2, 5) === @set leftendpoint(int) = -2 @test Interval{:open, :closed}(1, 2) === @set rightendpoint(int) = 2 @test Interval{:closed, :closed}(1, 5) === @set first(closedendpoints(int)) = true diff --git a/test/test_functionlenses.jl b/test/test_functionlenses.jl index 942a0633..e3c4bd13 100644 --- a/test/test_functionlenses.jl +++ b/test/test_functionlenses.jl @@ -341,9 +341,9 @@ end test_getset_laws(lens, Time(1, 2, 3, 4, 5, 6), rand(0:23), rand(0:23)) end @testset for x in [DateTime(2020, 1, 2, 3, 4, 5, 6), Date(2020, 1, 2)] - test_getset_laws(yearmonth, x, (rand(1:5000), rand(1:12)), (rand(1:5000), rand(1:12))) - test_getset_laws(monthday, x, (rand(1:12), rand(1:28)), (rand(1:12), rand(1:28))) - test_getset_laws(yearmonthday, x, (rand(1:5000), rand(1:12), rand(1:28)), (rand(1:5000), rand(1:12), rand(1:28))) + test_getset_laws(yearmonth, x, (rand(1:5000), rand(1:12) |> Int8), (rand(1:5000), rand(1:12))) + test_getset_laws(monthday, x, (rand(1:12), rand(1:28) |> Int8), (rand(1:12), rand(1:28))) + test_getset_laws(yearmonthday, x, (rand(1:5000), rand(1:12) |> Int8, rand(1:28)), (rand(1:5000), rand(1:12), rand(1:28))) end @testset for x in [DateTime(2020, 1, 2, 3, 4, 5, 6), Date(2020, 1, 2), Time(1, 2, 3, 4, 5, 6)]