Skip to content

Commit

Permalink
Deprecate Base.function_module in favor of parentmodule
Browse files Browse the repository at this point in the history
  • Loading branch information
ararslan committed Jan 18, 2018
1 parent 4aefe2a commit 300ebb6
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 15 deletions.
4 changes: 2 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -952,8 +952,8 @@ Deprecated or removed
have been deprecated. Subtypes of `AbstractArray` that implement the newly introduced strided
array interface should define their own `strides` method ([#25321]).

* `module_parent` and `Base.datatype_module` have been deprecated in favor of `parentmodule`
([#TODO]).
* `module_parent`, `Base.datatype_module`, and `Base.function_module` have been deprecated
in favor of `parentmodule` ([#TODO]).

* `rand(t::Tuple{Vararg{Int}})` is deprecated in favor of `rand(Float64, t)` or `rand(t...)`;
`rand(::Tuple)` will have another meaning in the future ([#25429], [#25278]).
Expand Down
4 changes: 2 additions & 2 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2819,8 +2819,8 @@ export readandwrite
@deprecate module_parent(m::Module) parentmodule(m)
@deprecate datatype_module(t::DataType) parentmodule(t) false
@deprecate datatype_module(t::UnionAll) parentmodule(t) false
@deprecate Base.function_module(f::Function) parentmodule(f)
@deprecate Base.function_module(f, t) parentmodule(f, t)
@deprecate function_module(f::Function) parentmodule(f) false
@deprecate function_module(f, t) parentmodule(f, t) false

# PR #25196
@deprecate_binding ObjectIdDict IdDict{Any,Any}
Expand Down
8 changes: 4 additions & 4 deletions base/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -983,19 +983,19 @@ function functionloc(@nospecialize(f))
end

"""
Base.function_module(f::Function) -> Module
parentmodule(f::Function) -> Module
Determine the module containing the (first) definition of a generic
function.
"""
function_module(f::Function) = parentmodule(typeof(f))
parentmodule(f::Function) = parentmodule(typeof(f))

"""
Base.function_module(f::Function, types) -> Module
parentmodule(f::Function, types) -> Module
Determine the module containing a given definition of a generic function.
"""
function function_module(@nospecialize(f), @nospecialize(types))
function parentmodule(@nospecialize(f), @nospecialize(types))
m = methods(f, types)
if isempty(m)
error("no matching methods")
Expand Down
2 changes: 0 additions & 2 deletions doc/src/base/base.md
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,6 @@ Base.propertynames
Base.datatype_name
Base.isconst
Base.function_name
Base.function_module(::Function)
Base.function_module(::Any, ::Any)
Base.functionloc(::Any, ::Any)
Base.functionloc(::Method)
Base.@functionloc
Expand Down
10 changes: 5 additions & 5 deletions test/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,11 @@ let
@test Base.binding_module(@__MODULE__, :a9475) == TestMod7648.TestModSub9475
@test Base.binding_module(@__MODULE__, :c7648) == TestMod7648
@test Base.function_name(foo7648) == :foo7648
@test Base.function_module(foo7648, (Any,)) == TestMod7648
@test Base.function_module(foo7648) == TestMod7648
@test Base.function_module(foo7648_nomethods) == TestMod7648
@test Base.function_module(foo9475, (Any,)) == TestMod7648.TestModSub9475
@test Base.function_module(foo9475) == TestMod7648.TestModSub9475
@test parentmodule(foo7648, (Any,)) == TestMod7648
@test parentmodule(foo7648) == TestMod7648
@test parentmodule(foo7648_nomethods) == TestMod7648
@test parentmodule(foo9475, (Any,)) == TestMod7648.TestModSub9475
@test parentmodule(foo9475) == TestMod7648.TestModSub9475
@test parentmodule(Foo7648) == TestMod7648
@test Base.datatype_name(Foo7648) == :Foo7648
@test basename(functionloc(foo7648, (Any,))[1]) == "reflection.jl"
Expand Down

0 comments on commit 300ebb6

Please sign in to comment.