def get_callable_fq_for_code(code, locals_dict = None):
"""Determines the function belonging to a given code object in a fully qualified fashion.
Returns a tuple consisting of
- the callable
- a list of classes and inner classes, locating the callable (like a fully qualified name)
- the corresponding self object, if the callable is a method
"""
if code in _code_callable_dict:
res = _code_callable_dict[code]
if not res[0] is None or locals_dict is None:
return res
md = getmodule(code)
if not md is None:
nesting = []
res, slf = _get_callable_fq_for_code(code, md, md, False, nesting, set())
if res is None and not locals_dict is None:
nesting = []
res, slf = _get_callable_from_locals(code, locals_dict, md, False, nesting)
else:
_code_callable_dict[code] = (res, nesting, slf)
return res, nesting, slf
else:
return None, None, None
评论列表
文章目录