How to get count of current methods in a package's methodtable?

question

#1

The only tools I know to get information about methods are:

  • methods()
  • methodswith()
  • (kind of) fieldnames()

How do you get information about the underlying method table though?

Is there a way to see how many methods there are in a table (at some point in time)?


#2

Something that gets you close to this is:

function get_all_symbols(cur_package::Module)
  all_symbols = []

  for cur_name in cur_package.names(cur_package, true)
    Base.isidentifier(cur_name) || continue
    in(cur_name, (Symbol(cur_package), :eval)) && continue

    push!(all_symbols, cur_name)
  end

  all_symbols
end

#3

You can check whether a binding is callable with isa(x, Base.Callable), which I believe implies it should have a method table entry.


#4

Would this be able to differentiate:

  • foo(bar::Baz)
  • foo(bar::Fizz.Buzz)

?


#5

Might have just answered that myself. Current func I’m working with:

function get_method_count(cur_package::Module)
  method_count = 0

  for cur_name in cur_package.names(cur_package, true)
    isdefined(cur_package, cur_name) || continue
    cur_obj = getfield(cur_package, cur_name)

    isa(cur_obj, Base.Callable) || continue
    method_count += length(methods(cur_obj))
  end

  method_count
end

#6

A bit random question but do you intentionally put blank lines between all lines of code? It makes it difficult to read it.