base.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:offshoot 作者: SerpentAI 项目源码 文件源码
def file_contains_pluggable(file_path, pluggable):
    plugin_class = None

    try:
        with open(file_path, "r") as f:
            syntax_tree = ast.parse(f.read())
    except FileNotFoundError:
        return [False, None]

    for statement in ast.walk(syntax_tree):
        if isinstance(statement, ast.ClassDef):
            class_name = statement.name

            bases = list(map(lambda b: b.id if isinstance(b, ast.Name) else b.attr, statement.bases))

            if pluggable in bases:
                plugin_class = class_name

    return [plugin_class is not None, plugin_class]
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号