parser.py 文件源码

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

项目:SoS 作者: vatlab 项目源码 文件源码
def get_type_hint(stmt):
    try:
        ns = {'file_target': file_target, 'sos_targets': sos_targets,
                'path': path, 'paths': paths}
        # let us grab the part before =
        exec(stmt.split('=', 1)[0], ns)
        # if it can compile, it can be typetrait, or something like
        #
        # python: input='a'
        #
        # where input is recognied
        #
        if '__annotations__' in ns and all(not isinstance(x, types.BuiltinFunctionType) and callable(x) for x in ns['__annotations__'].values()):
            return ns.popitem()[1]
        return None
    except:
        # if cannot compile, not type hint
        #
        # python: args='whatever'
        return None
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号