Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if not isinstance(target, FunctionType):
raise UnsupportedForCompilation("Only functions can be compiled by this decorator")
if _evaldict is None or _evaldict is True:
if _evaldict is True:
frame = _get_callerframe(offset=1)
else:
frame = _get_callerframe()
_evaldict, _ = extract_module_and_evaldict(frame)
# first make sure that source code is available for compilation
try:
lines = getsource(target)
except (OSError, IOError) as e:
if 'could not get source code' in str(e):
raise SourceUnavailable(target, e)
else:
raise
# compile all references first
try:
# python 3
func_closure = target.__closure__
func_code = target.__code__
except AttributeError:
# python 2
func_closure = target.func_closure
func_code = target.func_code
# Does not work: if `self.i` is used in the code, `i` will appear here
# if func_code is not None:
# for name in func_code.co_names: