Skip to content

re-exported deprecated symbols not marked deprecated #42

Closed
@t-bltg

Description

@t-bltg
module Foo
  module Types
    export OldType, NewType
    const OldType = Union{Int, Nothing}
    const NewType = Union{Int, Missing}
  end
  using Reexport
  @reexport using .Types
  Base.@deprecate_binding OldType NewType
end
import .Foo

julia> Base.isdeprecated(Main, :OldType)
false  # expected Main.OldType to be also deprecated, since `Main.Foo.OldType` is
julia> Base.isdeprecated(Foo, :OldType)
true

Related to JuliaTesting/Aqua.jl#89, since this is the root cause of the UnicodePlots test suite warnings thrown when using Aqua.

Running the UnicodePlots test suite:

pkg> test UnicodePlots
[...]
tst_imageplot.jl |    2      2
WARNING: importing deprecated binding Colors.RGB1 into ImageCore.
WARNING: importing deprecated binding Colors.RGB1 into ImageBase.
WARNING: Colors.RGB1 is deprecated, use XRGB instead.
  likely near ~/.julia/packages/UnicodePlots/vtIuF/test/tst_quality.jl:1
WARNING: importing deprecated binding Colors.RGB4 into ImageCore.
WARNING: importing deprecated binding Colors.RGB4 into ImageBase.
WARNING: Colors.RGB4 is deprecated, use RGBX instead.
  likely near ~/.julia/packages/UnicodePlots/vtIuF/test/tst_quality.jl:1
WARNING: importing deprecated binding ImageCore.permuteddimsview into ImageBase.
WARNING: ImageCore.permuteddimsview is deprecated, use PermutedDimsArray instead.
  likely near ~/.julia/packages/UnicodePlots/vtIuF/test/tst_quality.jl:1
Test Summary:  | Pass  Total
tst_quality.jl |    7      7
[...]

These warnings are triggered in Aqua.jl/src/unbound_args.jl, which maps to the failing line in julia/stdlib/Test/src/Test.jl, because the re-exported symbol are not marked as deprecated in the @reexport calling module.

I tried patching Reexport to call Base.deprecate(mod, sym) in the @reexport scope but it current fails these @deprecate_binding lines with ERROR: LoadError: cannot assign a value to variable ColorTypes.RGB1 from module Colors (so this would be breaking I guess).

diff --git a/src/Reexport.jl b/src/Reexport.jl
index 58d17d8..b5d18f4 100644
--- a/src/Reexport.jl
+++ b/src/Reexport.jl
@@ -37,15 +37,27 @@ function reexport(m::Module, ex::Expr)
         modules = Any[e.args[end] for e in ex.args]
     end
 
-    names = GlobalRef(@__MODULE__, :exported_names)
+    exp_names = GlobalRef(@__MODULE__, :exported_names)
+    dep_names = GlobalRef(@__MODULE__, :deprecated_names)
+
     out = Expr(:toplevel, ex)
     for mod in modules
-        push!(out.args, :($eval($m, Expr(:export, $names($mod)...))))
+        push!(
+            out.args,
+            quote
+                $eval($m, Expr(:export, $exp_names($mod)...))
+                foreach(n -> Base.deprecate($m, n), $dep_names($mod))
+            end
+        )
     end
     return out
 end
 
-exported_names(m::Module) = filter!(x -> Base.isexported(m, x), names(m; all=true, imported=true))
+exported_names(m::Module) =
+    filter!(x -> Base.isexported(m, x), names(m; all=true, imported=true))
+
+deprecated_names(m::Module) =
+    filter!(x -> Base.isdeprecated(m, x), names(m; all=true, imported=true))
 
 export @reexport

Related: #28.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions