Skip to content

Commit

Permalink
Deprecate Base.datatype_name to a nameof method
Browse files Browse the repository at this point in the history
  • Loading branch information
ararslan committed Jan 22, 2018
1 parent 0fa959b commit a35c2d4
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 11 deletions.
4 changes: 2 additions & 2 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -965,8 +965,8 @@ Deprecated or removed
* `findin(a, b)` has been deprecated in favor of `findall(occursin(b), a)` ([#24673]).

* `module_name` has been deprecated in favor of a new, general `nameof` function. Similarly,
the unexported `Base.function_name` has been deprecated in favor of a `nameof` method
([#25622]).
the unexported `Base.function_name` and `Base.datatype_name` have been deprecated in favor
of `nameof` methods ([#25622]).

* The module `Random.dSFMT` is renamed `Random.DSFMT` ([#25567]).

Expand Down
2 changes: 2 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1627,6 +1627,8 @@ export readandwrite
# PR #25622
@deprecate module_name(m::Module) nameof(m)
@deprecate function_name(f::Function) nameof(f) false
@deprecate datatype_name(t::DataType) nameof(t) false
@deprecate datatype_name(t::UnionAll) nameof(t) false

# PR #25196
@deprecate_binding ObjectIdDict IdDict{Any,Any}
Expand Down
11 changes: 6 additions & 5 deletions base/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,10 @@ fieldnames(t::UnionAll) = fieldnames(unwrap_unionall(t))
fieldnames(t::Type{<:Tuple}) = Int[n for n in 1:fieldcount(t)]

"""
Base.datatype_name(t) -> Symbol
nameof(t::DataType) -> Symbol
Get the name of a (potentially UnionAll-wrapped) `DataType` (without its parent module) as a symbol.
Get the name of a (potentially `UnionAll`-wrapped) `DataType` (without its parent module)
as a symbol.
# Examples
```jldoctest
Expand All @@ -155,12 +156,12 @@ julia> module Foo
end
Foo
julia> Base.datatype_name(Foo.S{T} where T)
julia> nameof(Foo.S{T} where T)
:S
```
"""
datatype_name(t::DataType) = t.name.name
datatype_name(t::UnionAll) = datatype_name(unwrap_unionall(t))
nameof(t::DataType) = t.name.name
nameof(t::UnionAll) = nameof(unwrap_unionall(t))

"""
parentmodule(t::DataType) -> Module
Expand Down
2 changes: 1 addition & 1 deletion doc/src/base/base.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ Base.isimmutable
Base.isabstracttype
Base.isprimitivetype
Base.isstructtype
Base.datatype_name
Base.nameof(::DataType)
Base.fieldnames
Base.fieldname
```
Expand Down
2 changes: 1 addition & 1 deletion stdlib/Dates/src/parse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function character_codes(directives::SimpleVector)
return letters
end

genvar(t::DataType) = Symbol(lowercase(string(Base.datatype_name(t))))
genvar(t::DataType) = Symbol(lowercase(string(nameof(t))))

"""
tryparsenext_core(str::AbstractString, pos::Int, len::Int, df::DateFormat, raise=false)
Expand Down
2 changes: 1 addition & 1 deletion stdlib/REPL/src/LineEdit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ const COMMAND_GROUPS =

const COMMAND_GROUP = Dict(command=>group for (group, commands) in COMMAND_GROUPS for command in commands)
command_group(command::Symbol) = get(COMMAND_GROUP, command, :nogroup)
command_group(command::Function) = command_group(Base.nameof(command))
command_group(command::Function) = command_group(nameof(command))

# return true if command should keep active a region
function preserve_active(command::Symbol)
Expand Down
2 changes: 1 addition & 1 deletion test/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ let
@test parentmodule(foo9475, (Any,)) == TestMod7648.TestModSub9475
@test parentmodule(foo9475) == TestMod7648.TestModSub9475
@test parentmodule(Foo7648) == TestMod7648
@test Base.datatype_name(Foo7648) == :Foo7648
@test nameof(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 a35c2d4

Please sign in to comment.