Skip to content

Commit ea252f0

Browse files
authored
deprecate convert (#397)
1 parent e047fd8 commit ea252f0

File tree

5 files changed

+15
-12
lines changed

5 files changed

+15
-12
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ChainRulesCore"
22
uuid = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
3-
version = "0.10.12"
3+
version = "0.10.13"
44

55
[deps]
66
Compat = "34da2185-b29b-5c13-b0c7-acf172513d20"

src/deprecated.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import Base: convert
2+
13
Base.@deprecate_binding NO_FIELDS NoTangent()
24

35
const EXTERN_DEPRECATION = "`extern` is deprecated, use `unthunk` or `backing` instead, " *
@@ -56,4 +58,8 @@ for T in (:Thunk, :InplaceableThunk)
5658
end
5759

5860

59-
Base.@deprecate InplaceableThunk(t::Thunk, add!) InplaceableThunk(add!, t)
61+
Base.@deprecate InplaceableThunk(t::Thunk, add!) InplaceableThunk(add!, t)
62+
63+
Base.@deprecate convert(::Type{<:Tuple}, t::Tangent{<:Any, <:Tuple}) backing(t)
64+
Base.@deprecate convert(::Type{<:NamedTuple}, t::Tangent{<:Any, <:NamedTuple}) backing(t)
65+
Base.@deprecate convert(::Type{<:Dict}, t::Tangent{<:Dict, <:Dict}) backing(t)

src/differentials/composite.jl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,6 @@ function Base.show(io::IO, comp::Tangent{P}) where P
6868
end
6969
end
7070

71-
Base.convert(::Type{<:NamedTuple}, comp::Tangent{<:Any, <:NamedTuple}) = backing(comp)
72-
Base.convert(::Type{<:Tuple}, comp::Tangent{<:Any, <:Tuple}) = backing(comp)
73-
Base.convert(::Type{<:Dict}, comp::Tangent{<:Dict, <:Dict}) = backing(comp)
74-
7571
Base.getindex(comp::Tangent, idx) = getindex(backing(comp), idx)
7672

7773
# for Tuple

test/deprecated.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,10 @@ end
3636

3737
@testset "Deprecated: Inplacable Thunk argument order" begin
3838
@test (@test_deprecated InplaceableThunk(@thunk([1]), x->x.+=1)) isa InplaceableThunk
39-
end
39+
end
40+
41+
@testset "Deprecated: convert from Tangent" begin
42+
@test (@test_deprecated convert(NamedTuple, Tangent{Foo}(x=2.5))) == (; x=2.5)
43+
@test (@test_deprecated convert(Tuple, Tangent{Tuple{Float64,}}(2.0))) == (2.0,)
44+
@test (@test_deprecated convert(Dict, Tangent{Dict}(Dict(4 => 3)))) == Dict(4 => 3)
45+
end

test/differentials/composite.jl

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@ end
2222
@testset "empty types" begin
2323
@test typeof(Tangent{Tuple{}}()) == Tangent{Tuple{}, Tuple{}}
2424
end
25-
@testset "convert" begin
26-
@test convert(NamedTuple, Tangent{Foo}(x=2.5)) == (; x=2.5)
27-
@test convert(Tuple, Tangent{Tuple{Float64,}}(2.0)) == (2.0,)
28-
@test convert(Dict, Tangent{Dict}(Dict(4 => 3))) == Dict(4 => 3)
29-
end
3025

3126
@testset "==" begin
3227
@test Tangent{Foo}(x=0.1, y=2.5) == Tangent{Foo}(x=0.1, y=2.5)

0 commit comments

Comments
 (0)