Getting base type name in julia 1.6

I am trying to get the base type name of an instance of a parametric type.
In julia up to 1.5 I would use typeof(obj).name which would do what I want. But something changed in current nightlies.

For example, in 1.6:

               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.6.0-DEV.1647 (2020-12-03)
 _/ |\__'_|_|_|\__'_|  |  Commit 49b8e61a80* (7 days old master)
|__/                   |

julia> using GLM

julia> y=rand(100); X=rand(100,4);

julia> m=lm(X,y)
LinearModel{GLM.LmResp{Vector{Float64}}, GLM.DensePredChol{Float64, LinearAlgebra.Cholesky{Float64, Matrix{Float64}}}}:

Coefficients:
────────────────────────────────────────────────────────────────
        Coef.  Std. Error     t  Pr(>|t|)   Lower 95%  Upper 95%
────────────────────────────────────────────────────────────────
x1  0.0448507   0.0959875  0.47    0.6414  -0.145683    0.235384
x2  0.415308    0.0970493  4.28    <1e-04   0.222667    0.607949
x3  0.243972    0.091193   2.68    0.0088   0.062955    0.424988
x4  0.157658    0.0943933  1.67    0.0981  -0.0297113   0.345027
────────────────────────────────────────────────────────────────

julia> typeof(m).name
typename(LinearModel)

But the same code in julia 1.5 gives

julia> typeof(m).name
LinearModel

Is there a generic way to get β€œLinearModel” that works in both julia versions?

1 Like

It is recommended to use accessors like Base.typename. I think that it’s just the printing that changed, it is really the same thing.

What do you need this for? If you just want a symbol for printing, look at nameof.

2 Likes

Thanks @Tamas_Papp!
nameof(typeof(m)) is just what I needed.

1 Like

Also notice that

julia> typeof(m).name |> typeof
Core.TypeName

If you want to access where the actual name is stored, then it’s

julia> typeof(m).name.name
:LinearModel

This is the same in v1.5.3 and v1.6.0-DEV.

2 Likes

But, of course, may change at any point without prior notice as it is an internal implementation detail.

1 Like