code: def _detect_function_free_vars(fn):
      """Detect free vars in any Python function."""
      assert isinstance(fn, types.FunctionType) or isinstance(
          fn, types.MethodType
      ), f"The input should be of Python function type. Got type: {type(fn)}."
  
      queue = collections.deque([fn])
      fn_map = dict()
  
      # Perform BFS over functions to get free vars
      while queue:
          obj = queue.popleft()
          signature = _make_callable_signature(obj)
          if signature not in fn_map:
              free_vars = _search_callable_free_vars(obj)
              if not free_vars:
                  continue
              fn_map[signature] = free_vars
              for var in free_vars:
                  # Only search callable free vars
                  if var.is_function:
                      obj = var.obj
                      if _make_callable_signature(obj) not in fn_map:
                          queue.append(obj)
  
      # func_name -> namedtupe FreeVar
      return fn_map
  
file_path: tensorflow/tensorflow/core/function/capture/free_vars_detect.py
imports: import builtins
  import collections
  import functools
  import inspect
  import types
  from tensorflow.python.autograph.pyct import anno
  from tensorflow.python.autograph.pyct import inspect_utils
  from tensorflow.python.autograph.pyct import naming
  from tensorflow.python.autograph.pyct import parser
  from tensorflow.python.autograph.pyct import qual_names
  from tensorflow.python.autograph.pyct import transformer
  from tensorflow.python.autograph.pyct.static_analysis import activity
label_desc: Use image node_id 7 for calling a global function with example usage: _detect_function_free_vars(fn) and returns: fn_map