Is there a way to get all the types defined in a module? For instance I am using DifferentialEquations.jl a lot and I’d like to have a list of all the types defined in that module. I feel like it would help me to have an overview of what’s going on in the code and see how good julia programmers structure their code. Also, knowing that a type exists without having to dig in the doc might help to reuse types.
Thanks
You can get a list of all the names of “things” defined in a module using the names function. It is then just a matter of filtering the ones you want based on their types. Since types themselves are of type DataType, this should do the trick:
function print_types(modul)
for name in names(modul)
getfield(modul, name) isa DataType && println(name)
end
end
For example for module Pkg, we get
julia> using Pkg
julia> print_types(Pkg)
PackageMode
RegistrySpec
UpgradeLevel
(That being said, I’m not entirely sure that this will help you better understand the API of a module. Perhaps either the documentation or existing examples would be better to learn how to use DiffEq…)
Thanks, that helps. The function print_types() can be buggy on some modules (e.g. gives me an UndefVarError for DifferentialEquations) but it pointed me toward names() which gives me what I wanted.
function print_alltypes(modul::Module)
### All objects and its types into a Module
for name in names(modul)
objeto=getfield(modul,name)
tupla=supertypes(typeof(objeto))
println("Objet ", objeto, "---", "type ",tupla[2])
end
end