I'm working on a code analyzer and I'm trying to identify all the class types referenced within a function or class in Python.
For example say I have this class:
import collections
Bar = collections.namedtuple('Bar', ['bar'])
Baz = collections.namedtuple('Baz', ['baz'])
class Foo(object):
def get_bar(self):
return Bar(1)
def get_baz(self):
return Baz(2)
I'm looking for a way I can get types of the functions and classes. Something like this:
print(get_types(Foo.get_bar)) # ['Bar']
print(get_types(Foo.get_baz)) # ['Baz']
print(get_types(Foo)) # ['Bar','Baz']