Is there an isabstract(T) function where T is a DataType?


I wonder if there is a function that returns whether a type T is abstract or not. Any idea? I am trying to make a generator that returns all concrete types of a specific abstract type, and I need to check whether a certain type is abstract or not.

subtypes(T) is no good because it cannot differentiate between abstract types with no subtype (useful to have around for future support plans) and concrete types.



julia> isabstract
ERROR: UndefVarError: isabstract not defined


It’s not exported, which means that you have to explicitly do Base.isabstract as opposed to isabstract.

julia> Base.isabstract
ERROR: UndefVarError: isabstract not defined


Hmm… what version of Julia are you using? You should upgrade to the latest 0.6 release candidate.


I am using 0.5. Ok if I have to upgrade, then I will just manually enumerate them instead!


It’s in Compat

julia> using Compat

julia> isabstract
ERROR: UndefVarError: isabstract not defined

julia> Compat.isabstract
ERROR: UndefVarError: isabstract not defined



Ic. Thanks alot!

julia> Compat.TypeUtils.isabstract
isabstract (generic function with 3 methods)

julia> Compat.TypeUtils.isabstract(Int)

julia> Compat.TypeUtils.isabstract(Integer)


I was just searching for an isabstract function and also found Base.isabstract. However, I noticed Base.isabstract(Complex) == false which seems wrong to me.

But someone on Slack pointed out that there is isleaftype. I thought it might be useful to mention it here.


From v0.7:

julia> isleaftype(Array)
┌ Warning: `isleaftype` is deprecated, use `isconcrete` instead.
│   caller = top-level scope
└ @ Core :0


Even better!


why? it is not an abstract type.


It is a UnionAll type, which is NOT a concrete type. But I don’t know if not being concrete is the definition of an abstract type :thinking:


Abstract type = abstract type


But it isn’t. See the documentation for isconcrete:

Determine whether T is a concrete type, meaning it can have direct instances (values x such that typeof(x) === T).

I agree that the terminology is not the most intuitive. Similarly to topology, where a set not being open does not mean it is closed.