# Getting base type name in julia 1.6

**URL:** <https://discourse.julialang.org/t/getting-base-type-name-in-julia-1-6/51646>\
**Category:** General Usage\
**Created:** [December 11, 2020, 3:47am UTC](https://discourse.julialang.org/t/getting-base-type-name-in-julia-1-6/51646 "2020-12-11T03:47:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![AsafManela](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/asafmanela/32/4863_2.png) [@AsafManela](https://discourse.julialang.org/u/AsafManela)\
**Post date:** [December 11, 2020, 3:47am UTC](https://discourse.julialang.org/t/getting-base-type-name-in-julia-1-6/51646/1 "2020-12-11T03:47:47Z")

</div>

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:

```julia
               _
   _ _ _(_)_ | 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
julia> typeof(m).name
LinearModel

```

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

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [December 11, 2020, 1:37pm UTC](https://discourse.julialang.org/t/getting-base-type-name-in-julia-1-6/51646/2 "2020-12-11T13:37:52Z")

</div>

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`.

---

<div class="post-metadata">

**Author:** ![AsafManela](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/asafmanela/32/4863_2.png) [@AsafManela](https://discourse.julialang.org/u/AsafManela)\
**Post date:** [December 11, 2020, 3:16pm UTC](https://discourse.julialang.org/t/getting-base-type-name-in-julia-1-6/51646/3 "2020-12-11T15:16:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![FedericoStra](https://avatars.discourse-cdn.com/v4/letter/f/76d3ee/32.png) [@FedericoStra](https://discourse.julialang.org/u/FedericoStra)\
**Post date:** [December 11, 2020, 3:57pm UTC](https://discourse.julialang.org/t/getting-base-type-name-in-julia-1-6/51646/4 "2020-12-11T15:57:37Z")

</div>

Also notice that

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

```

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

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

```

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

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [December 12, 2020, 12:38pm UTC](https://discourse.julialang.org/t/getting-base-type-name-in-julia-1-6/51646/5 "2020-12-12T12:38:32Z")

</div>

> [@FedericoStra](#):
>
> If you want to access where the actual name is stored, then it’s
> 
> ```julia
> julia> typeof(m).name.name
> :LinearModel
> 
> ```
> 
> This is the same in v1.5.3 and v1.6.0-DEV.

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