Skip to content

Commit 20f933a

Browse files
authored
InteractiveUtils.jl: fixes issue where subtypes resolves bindings and causes deprecation warnings (#56306)
The current version of `subtypes` will throw deprecation errors even if no one is using the deprecated bindings. A similar bug was fixed in Aqua.jl - https://github.com/JuliaTesting/Aqua.jl/pull/89/files See discussion here: - JuliaIO/ImageMagick.jl#235 (for identifying the problem) - simonster/Reexport.jl#42 (for pointing to the issue in Aqua.jl) - https://github.com/JuliaTesting/Aqua.jl/pull/89/files (for the fix in Aqua.jl) This adds the `isbindingresolved` test to the `subtypes` function to avoid throwing deprecation warnings. It also adds a test to check that this doesn't happen. --- On the current master branch (before the fix), the added test shows: ``` WARNING: using deprecated binding InternalModule.MyOldType in OuterModule. , use MyType instead. Subtypes and deprecations: Test Failed at /home/dgleich/devextern/julia/usr/share/julia/stdlib/v1.12/Test/src/Test.jl:932 Expression: isempty(stderr_content) Evaluated: isempty("WARNING: using deprecated binding InternalModule.MyOldType in OuterModule.\n, use MyType instead.\n") Test Summary: | Fail Total Time Subtypes and deprecations | 1 1 2.8s ERROR: LoadError: Some tests did not pass: 0 passed, 1 failed, 0 errored, 0 broken. in expression starting at /home/dgleich/devextern/julia/stdlib/InteractiveUtils/test/runtests.jl:841 ERROR: Package InteractiveUtils errored during testing ``` --- Using the results of this pull request: ``` @test_nowarn subtypes(Integer); ``` passes without error. The other tests pass too.
1 parent c188e0c commit 20f933a

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

stdlib/InteractiveUtils/src/InteractiveUtils.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export apropos, edit, less, code_warntype, code_llvm, code_native, methodswith,
1616
import Base.Docs.apropos
1717

1818
using Base: unwrap_unionall, rewrap_unionall, isdeprecated, Bottom, summarysize,
19-
signature_type, format_bytes
19+
signature_type, format_bytes, isbindingresolved
2020
using Base.Libc
2121
using Markdown
2222

@@ -262,7 +262,7 @@ function _subtypes_in!(mods::Array, x::Type)
262262
m = pop!(mods)
263263
xt = xt::DataType
264264
for s in names(m, all = true)
265-
if isdefined(m, s) && !isdeprecated(m, s)
265+
if isbindingresolved(m, s) && !isdeprecated(m, s) && isdefined(m, s)
266266
t = getfield(m, s)
267267
dt = isa(t, UnionAll) ? unwrap_unionall(t) : t
268268
if isa(dt, DataType)

stdlib/InteractiveUtils/test/runtests.jl

+19
Original file line numberDiff line numberDiff line change
@@ -823,3 +823,22 @@ end
823823
@testset "Docstrings" begin
824824
@test isempty(Docs.undocumented_names(InteractiveUtils))
825825
end
826+
827+
# issue https://github.com/JuliaIO/ImageMagick.jl/issues/235
828+
module OuterModule
829+
module InternalModule
830+
struct MyType
831+
x::Int
832+
end
833+
834+
Base.@deprecate_binding MyOldType MyType
835+
836+
export MyType
837+
end
838+
using .InternalModule
839+
export MyType, MyOldType
840+
end # module
841+
@testset "Subtypes and deprecations" begin
842+
using .OuterModule
843+
@test_nowarn subtypes(Integer);
844+
end

0 commit comments

Comments
 (0)