Hi all,
I’m working on a Julia terminal application implementing some of python’s awesome rich terminal library.
Two of rich’s best features, in my opinion, are inspect
which prints out details and methods about a python object and tracebacks
which styles and organize error messages making them much easier to read.
I’m trying to implement these in Term.jl but struggling with find nice ways to introspect Julia code. I’ve looked at:
- https://towardsdatascience.com/runtime-introspection-julias-most-powerful-best-kept-secret-bf845e282367
- Reflection and introspection · The Julia Language
- Documentation · The Julia Language
- https://github.com/JuliaLang/julia/blob/bf534986350a991e4a1b29126de0342ffd76205e/base/docs/Docs.jl#L440-L455
but still struggle to get a few bits of information.
For instance given:
abstract type AA end
abstract type AbstractTest <: AA end
"""
Test
A test `struct` for inspection
"""
mutable struct Test <: AbstractTest
x::Int
y::String
end
Test(x) = Test(x[1], x[2])
I’m writing a function inspect
that spits out formatted information about Test
: inspect(Test)
using things like methods
, supertypes
, fieldnames
…
to get the docstring I’ve tried string(@doc my_type)
within my inspect
function, but that doesn’t work. If outside my inspect
function I call @doc Test
I can retrieve the docstring correctly, but when passing Test
as an argument to inspect
then @doc
fails.
I’ve seen that Docs.jl
has methods like metadata
, but I can’t find any good docs. Anyone has any idea on how to do this better?
Related, is there any docs on how the tracebacks are created in Julia and if there are methods to access them? In python you can have code that replaces the default tracebacks with ones you like, is there a way to do something similar in Julia?