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
评论列表
文章目录