From 6964570c89f818d8415bbdb76ce6e02969232539 Mon Sep 17 00:00:00 2001 From: Alex Arslan Date: Thu, 18 Jan 2018 11:33:15 -0800 Subject: [PATCH] Deprecate Base.datatype_name to a name method --- NEWS.md | 4 ++-- base/deprecated.jl | 4 ++-- base/reflection.jl | 11 ++++++----- stdlib/Dates/src/parse.jl | 2 +- test/reflection.jl | 2 +- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/NEWS.md b/NEWS.md index dceea4cdd0108..0acdf4d7f995b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -955,8 +955,8 @@ Deprecated or removed * The module `Random.dSFMT` is renamed `Random.DSFMT` ([#25567]). * `module_name` has been deprecated in favor of a new, general `name` function. Similarly, - the unexported `Base.function_name` has been deprecated in favor of a `name` method - ([#25622]). + the unexported `Base.function_name` and `Base.datatype_name` have been deprecated in favor + of `name` methods ([#25622]). * The generic implementations of `strides(::AbstractArray)` and `stride(::AbstractArray, ::Int)` have been deprecated. Subtypes of `AbstractArray` that implement the newly introduced strided diff --git a/base/deprecated.jl b/base/deprecated.jl index 21a5a0677404c..19697a1047a87 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -1614,8 +1614,8 @@ export readandwrite # PR 25622 @deprecate module_name(m::Module) name(m) @deprecate function_name(f::Function) name(f) false -@deprecate Base.datatype_name(t::DataType) name(t) -@deprecate Base.datatype_name(t::UnionAll) name(t) +@deprecate datatype_name(t::DataType) name(t) false +@deprecate datatype_name(t::UnionAll) name(t) false # PR #25196 @deprecate_binding ObjectIdDict IdDict{Any,Any} diff --git a/base/reflection.jl b/base/reflection.jl index dc7f76913f92f..e97150279cd4c 100644 --- a/base/reflection.jl +++ b/base/reflection.jl @@ -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 + name(t::Type) -> 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 @@ -155,12 +156,12 @@ julia> module Foo end Foo -julia> Base.datatype_name(Foo.S{T} where T) +julia> name(Foo.S{T} where T) :S ``` """ -datatype_name(t::DataType) = t.name.name -datatype_name(t::UnionAll) = datatype_name(unwrap_unionall(t)) +name(t::DataType) = t.name.name +name(t::UnionAll) = name(unwrap_unionall(t)) """ parentmodule(t::DataType) -> Module diff --git a/stdlib/Dates/src/parse.jl b/stdlib/Dates/src/parse.jl index 1b0e4165394c0..ea11368a71c3a 100644 --- a/stdlib/Dates/src/parse.jl +++ b/stdlib/Dates/src/parse.jl @@ -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(name(t)))) """ tryparsenext_core(str::AbstractString, pos::Int, len::Int, df::DateFormat, raise=false) diff --git a/test/reflection.jl b/test/reflection.jl index 5ccaafd5150d1..e6ff9797cb115 100644 --- a/test/reflection.jl +++ b/test/reflection.jl @@ -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 name(Foo7648) == :Foo7648 @test basename(functionloc(foo7648, (Any,))[1]) == "reflection.jl" @test first(methods(TestMod7648.TestModSub9475.foo7648)) == @which foo7648(5) @test TestMod7648 == @which foo7648