Skip to content

Commit

Permalink
Merge pull request #17810 from helgee/typename
Browse files Browse the repository at this point in the history
Add datatype_name function. Fix #17555
  • Loading branch information
vtjnash authored Aug 4, 2016
2 parents 76fedd3 + 78aa99e commit 043eb26
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions base/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ end
fieldnames(t::DataType) = Symbol[fieldname(t, n) for n in 1:nfields(t)]
fieldnames{T<:Tuple}(t::Type{T}) = Int[n for n in 1:nfields(t)]

"""
Base.datatype_name(t::DataType) -> Symbol
Get the name of a `DataType` (without its parent module) as a symbol.
"""
datatype_name(t::DataType) = t.name.name

"""
Base.datatype_module(t::DataType) -> Module
Expand Down
6 changes: 6 additions & 0 deletions doc/stdlib/base.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1355,6 +1355,12 @@ Reflection
Determine the module containing the definition of a ``DataType``\ .

.. function:: Base.datatype_name(t::DataType) -> Symbol

.. Docstring generated from Julia source
Get the name of a ``DataType`` (without its parent module) as a symbol.

.. function:: isconst([m::Module], s::Symbol) -> Bool

.. Docstring generated from Julia source
Expand Down
1 change: 1 addition & 0 deletions test/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ let
@test Base.function_module(foo9475, (Any,)) == TestMod7648.TestModSub9475
@test Base.function_module(foo9475) == TestMod7648.TestModSub9475
@test Base.datatype_module(Foo7648) == TestMod7648
@test Base.datatype_name(Foo7648) == :Foo7648
@test basename(functionloc(foo7648, (Any,))[1]) == "reflection.jl"
@test first(methods(TestMod7648.TestModSub9475.foo7648)) == @which foo7648(5)
@test TestMod7648 == @which foo7648
Expand Down

0 comments on commit 043eb26

Please sign in to comment.