diff --git a/README.md b/README.md index fdcd805c7b833..046020413f33a 100644 --- a/README.md +++ b/README.md @@ -291,6 +291,9 @@ Currently, the `@compat` macro supports the following syntaxes: * `ipermute!` is now `invpermute!` ([#25168]). +* `module_parent`, `Base.function_module`, and `Base.datatype_module` are now methods of + a new function called `parentmodule` ([#25629]). + ## New macros * `@__DIR__` has been added ([#18380]) @@ -470,3 +473,4 @@ includes this fix. Find the minimum version from there. [#25227]: https://github.com/JuliaLang/julia/issues/25227 [#25249]: https://github.com/JuliaLang/julia/issues/25249 [#25402]: https://github.com/JuliaLang/julia/issues/25402 +[#25629]: https://github.com/JuliaLang/julia/issues/25629 diff --git a/src/Compat.jl b/src/Compat.jl index c6a7f5bb0b683..7828c84e3d429 100644 --- a/src/Compat.jl +++ b/src/Compat.jl @@ -1296,6 +1296,15 @@ else @eval const $(Symbol("@error")) = Base.$(Symbol("@error")) end +@static if !isdefined(Base, :parentmodule) + parentmodule(m::Module) = Base.module_parent(m) + parentmodule(f::Function) = Base.function_module(f) + parentmodule(@nospecialize(f), @nospecialize(t)) = Base.function_module(f, t) + parentmodule(t::DataType) = Base.datatype_module(t) + parentmodule(t::UnionAll) = Base.datatype_module(Base.unwrap_unionall(t)) + export parentmodule +end + include("deprecated.jl") end # module Compat diff --git a/test/runtests.jl b/test/runtests.jl index 7c8480276267a..3069ee04a11e8 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1150,6 +1150,12 @@ if !isdefined(Base, Symbol("@info")) end end +# 0.7.0-DEV.3460 +@test parentmodule(Compat.Sys) == Compat +@test parentmodule(sin) == Base +@test parentmodule(sin, Tuple{Int}) == Base.Math +@test parentmodule(Int) == Core +@test parentmodule(Array) == Core if VERSION < v"0.6.0" include("deprecated.jl")