def decompile(obj):
"""
Decompile obj if it is a module object, a function or a
code object. If obj is a string, it is assumed to be the path
to a python module.
"""
if isinstance(obj, str):
return dec_module(obj)
if inspect.iscode(obj):
code = Code(obj)
return code.get_suite()
if inspect.isfunction(obj):
code = Code(obj.__code__)
defaults = obj.__defaults__
kwdefaults = obj.__kwdefaults__
return DefStatement(code, defaults, kwdefaults, obj.__closure__)
elif inspect.ismodule(obj):
return dec_module(obj.__file__)
else:
msg = "Object must be string, module, function or code object"
raise TypeError(msg)
评论列表
文章目录