Skip to content

Conversation

@mzgubic
Copy link
Member

@mzgubic mzgubic commented Jul 19, 2021

Closes #359


const CONVERT_DEPRECATION = "convert(::Type{T}, t::Tangent) is deprecated, use ChainRulesCore.backing(t) instead"

function Base.convert(::Type{<:NamedTuple}, comp::Tangent{<:Any, <:NamedTuple})
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Annoyingly it's not possible to @deprecate Base.convert..., i.e. adding the Base prefix gives the following error:

ERROR: LoadError: LoadError: LoadError: invalid usage of @deprecate
Stacktrace:
  [1] error(s::String)
    @ Base ./error.jl:33
  [2] var"@deprecate"(__source__::LineNumberNode, __module__::Module, old::Any, new::Any, ex::Any)
    @ Base ./deprecated.jl:62
  [3] var"@deprecate"(__source__::LineNumberNode, __module__::Module, old::Any, new::Any)
    @ Base ./deprecated.jl:39
  [4] include(mod::Module, _path::String)
    @ Base ./Base.jl:386
  [5] include(x::String)
    @ ChainRulesCore ~/JuliaEnvs/ChainRulesCore.jl/src/ChainRulesCore.jl:1
  [6] top-level scope
    @ ~/JuliaEnvs/ChainRulesCore.jl/src/ChainRulesCore.jl:35
  [7] include
    @ ./Base.jl:386 [inlined]
  [8] include_package_for_output(pkg::Base.PkgId, input::String, depot_path::Vector{String}, dl_load_path::Vector{String}, load_path::Vector{String}, concrete_deps::Vector{Pair{Base.PkgId, UInt64}}, source::Nothing)
    @ Base ./loading.jl:1235
  [9] top-level scope
    @ none:1
 [10] eval
    @ ./boot.jl:360 [inlined]
 [11] eval(x::Expr)
    @ Base.MainInclude ./client.jl:446
 [12] top-level scope
    @ none:1

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To deprecate something from another module you need to do import Base: convert
@deprecate doesn't support qualified names

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tried this but kept Base.convert 🤦

@codecov-commenter
Copy link

codecov-commenter commented Jul 19, 2021

Codecov Report

Merging #397 (056a775) into master (e047fd8) will increase coverage by 0.07%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #397      +/-   ##
==========================================
+ Coverage   91.99%   92.06%   +0.07%     
==========================================
  Files          15       15              
  Lines         637      643       +6     
==========================================
+ Hits          586      592       +6     
  Misses         51       51              
Impacted Files Coverage Δ
src/deprecated.jl 100.00% <ø> (ø)
src/differentials/composite.jl 82.75% <ø> (-0.44%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e047fd8...056a775. Read the comment docs.

Comment on lines 42 to 44
@test convert(NamedTuple, Tangent{Foo}(x=2.5)) == (; x=2.5)
@test convert(Tuple, Tangent{Tuple{Float64,}}(2.0)) == (2.0,)
@test convert(Dict, Tangent{Dict}(Dict(4 => 3))) == Dict(4 => 3)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@test convert(NamedTuple, Tangent{Foo}(x=2.5)) == (; x=2.5)
@test convert(Tuple, Tangent{Tuple{Float64,}}(2.0)) == (2.0,)
@test convert(Dict, Tangent{Dict}(Dict(4 => 3))) == Dict(4 => 3)
@test (@test_deprecated convert(NamedTuple, Tangent{Foo}(x=2.5))) == (; x=2.5)
@test (@test_deprecated convert(Tuple, Tangent{Tuple{Float64,}}(2.0))) == (2.0,)
@test (@test_deprecated convert(Dict, Tangent{Dict}(Dict(4 => 3)))) == Dict(4 => 3)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so as to mute the depwarnings in tests, and also ensure they are there

Copy link
Member

@oxinabox oxinabox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chang to using import Base: convert + @deprecate.
Then merge when you are happy.

@mzgubic mzgubic merged commit ea252f0 into master Jul 19, 2021
@mzgubic mzgubic deleted the mz/deprecate-convert branch July 19, 2021 11:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Remove convert for structured Tangent?

4 participants