I'm trying to build a dependency tree based on classes that are used inside methods of another class. So not the parent classes. For this i want to check if a method is using any classes that inherits from a special class named Table
.
Example:
class TestTableOne(Table):
"""Class for testing table loader"""
def source(self):
source_file = os.path.join('data',
'test_table_one.csv')
return pd.read_csv(source_file, dtype=dtype, converters=converters)
def output(self):
output_path = 'out/path'
return output_path
def post_processors(self):
return [
drop_age_column,
calculate_new_age
]
class TestTableTwo(Table):
"""Class for testing tables loader"""
def source(self):
return TestTableOne.fetch()
def output(self):
output_path = os.path.join(tempfile.mkdtemp(),
'output',
self.get_cached_filename('test_table_one', 'pkl')
)
return output_path
def something_does_nothing(self, table):
result = TestTableOne.get()
return result
def post_processors(self):
return [
self.something_does_nothing
]
Here i want to be able to check if TestTableTwo.source
is dependent on any other classes that inherits from Table
, in this case TestTableOne
.
So i wan to ask something similar to inspect.classes_that_appears_in(TestTableTwo.source)
and get [TestTableOne]
Is this possible in python? Im using python 3 btw.