不编译代码的答案是使用pysmell或类似的。
鉴于:
# base.py
class Base(object):
def __init__(self, name):
self.name = name
class First(Base):
def __init__(self, name="first"):
super(First, self).__init__(name)
class Second(First):
def __init__(self, name="second"):
super(Second, self).__init__(name)
class Third(Second):
def __init__(self, name="third"):
super(Third, self).__init__(name)
t = Third()
运行pysmell base.py
生成一个 PYSMELLTAGS 文件,如下所示:
{'CLASSES': {'base.Base': {'bases': ['object'],
'constructor': ['name'],
'docstring': '',
'methods': [],
'properties': ['name']},
'base.First': {'bases': ['base.Base'],
'constructor': ["name='first'"],
'docstring': '',
'methods': [],
'properties': []},
'base.Second': {'bases': ['base.First'],
'constructor': ["name='second'"],
'docstring': '',
'methods': [],
'properties': []},
'base.Third': {'bases': ['base.Second'],
'constructor': ["name='third'"],
'docstring': '',
'methods': [],
'properties': []}},
'CONSTANTS': ['base.t'],
'FUNCTIONS': [],
'HIERARCHY': ['base'],
'POINTERS': {}}
我相信这将有助于 OP 实现识别从其他类派生的类的目标。