I need a way to imitate the functionality of the inspect module from python.
I want to know the list of parameters of a functions, check if there are default values or not, and check if it accepts kwargs or not.
To get all the possible signatures of a function foo you can do methods(foo). This does not tell you default values of key-word arguments. I donβt know how to get those.
julia> foo(x; y=5) = x+y
foo (generic function with 1 method)
julia> foo(x::AbstractVector, z::Int) = z*x
foo (generic function with 2 methods)
julia> methods(foo)
# 2 methods for generic function "foo":
[1] foo(x::AbstractArray{T,1} where T, z::Int64) in Main at REPL[2]:1
[2] foo(x; y) in Main at REPL[1]:1
Callable structs would definitely be a better way to handle this. You should definitely only resort to reading the method table when you really really need to.