Skip to content

Commit b262a61

Browse files
committed
Deprecate Base.datatype_name to a nameof method
1 parent 4006e34 commit b262a61

7 files changed

Lines changed: 14 additions & 11 deletions

File tree

NEWS.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -965,8 +965,8 @@ Deprecated or removed
965965
* `findin(a, b)` has been deprecated in favor of `findall(occursin(b), a)` ([#24673]).
966966

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

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

base/deprecated.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1627,6 +1627,8 @@ export readandwrite
16271627
# PR #25622
16281628
@deprecate module_name(m::Module) nameof(m)
16291629
@deprecate function_name(f::Function) nameof(f) false
1630+
@deprecate datatype_name(t::DataType) nameof(t) false
1631+
@deprecate datatype_name(t::UnionAll) nameof(t) false
16301632

16311633
# PR #25196
16321634
@deprecate_binding ObjectIdDict IdDict{Any,Any}

base/reflection.jl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,10 @@ fieldnames(t::UnionAll) = fieldnames(unwrap_unionall(t))
143143
fieldnames(t::Type{<:Tuple}) = Int[n for n in 1:fieldcount(t)]
144144

145145
"""
146-
Base.datatype_name(t) -> Symbol
146+
nameof(t::DataType) -> Symbol
147147
148-
Get the name of a (potentially UnionAll-wrapped) `DataType` (without its parent module) as a symbol.
148+
Get the name of a (potentially `UnionAll`-wrapped) `DataType` (without its parent module)
149+
as a symbol.
149150
150151
# Examples
151152
```jldoctest
@@ -155,12 +156,12 @@ julia> module Foo
155156
end
156157
Foo
157158
158-
julia> Base.datatype_name(Foo.S{T} where T)
159+
julia> nameof(Foo.S{T} where T)
159160
:S
160161
```
161162
"""
162-
datatype_name(t::DataType) = t.name.name
163-
datatype_name(t::UnionAll) = datatype_name(unwrap_unionall(t))
163+
nameof(t::DataType) = t.name.name
164+
nameof(t::UnionAll) = nameof(unwrap_unionall(t))
164165

165166
"""
166167
parentmodule(t::DataType) -> Module

doc/src/base/base.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ Base.isimmutable
152152
Base.isabstracttype
153153
Base.isprimitivetype
154154
Base.isstructtype
155-
Base.datatype_name
155+
Base.nameof(::DataType)
156156
Base.fieldnames
157157
Base.fieldname
158158
```

stdlib/Dates/src/parse.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function character_codes(directives::SimpleVector)
1616
return letters
1717
end
1818

19-
genvar(t::DataType) = Symbol(lowercase(string(Base.datatype_name(t))))
19+
genvar(t::DataType) = Symbol(lowercase(string(nameof(t))))
2020

2121
"""
2222
tryparsenext_core(str::AbstractString, pos::Int, len::Int, df::DateFormat, raise=false)

stdlib/REPL/src/LineEdit.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ const COMMAND_GROUPS =
219219

220220
const COMMAND_GROUP = Dict(command=>group for (group, commands) in COMMAND_GROUPS for command in commands)
221221
command_group(command::Symbol) = get(COMMAND_GROUP, command, :nogroup)
222-
command_group(command::Function) = command_group(Base.nameof(command))
222+
command_group(command::Function) = command_group(nameof(command))
223223

224224
# return true if command should keep active a region
225225
function preserve_active(command::Symbol)

test/reflection.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ let
273273
@test parentmodule(foo9475, (Any,)) == TestMod7648.TestModSub9475
274274
@test parentmodule(foo9475) == TestMod7648.TestModSub9475
275275
@test parentmodule(Foo7648) == TestMod7648
276-
@test Base.datatype_name(Foo7648) == :Foo7648
276+
@test nameof(Foo7648) == :Foo7648
277277
@test basename(functionloc(foo7648, (Any,))[1]) == "reflection.jl"
278278
@test first(methods(TestMod7648.TestModSub9475.foo7648)) == @which foo7648(5)
279279
@test TestMod7648 == @which foo7648

0 commit comments

Comments
 (0)