Skip to content

Commit

Permalink
Add parentmodule
Browse files Browse the repository at this point in the history
  • Loading branch information
ararslan authored and fredrikekre committed Jan 19, 2018
1 parent a84c596 commit 91fbb6f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down Expand Up @@ -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
9 changes: 9 additions & 0 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1290,6 +1290,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
6 changes: 6 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 91fbb6f

Please sign in to comment.