code: def _get_self_obj_from_closure(fn):
      """Get the object that `self` keyword refers to within a function.
  
      Args:
        fn: A python function object
  
      Returns:
        A class object that `self` refers to. Return None if not found.
  
      Here is an example demonstrating how this helper function works.
  
      ```
      class Foo():
  
        def __init__(self):
          self.val = 1
  
        def bar(self):
          x = 2
  
          def fn():
            return self.val + x
  
          return fn
  
      foo = Foo()
      fn = foo.bar()
      self_obj = _get_self_obj_from_closure(fn)
      assert self_obj is foo
      ```
  
      The goal is to get the `self_obj` (foo) from `fn`, so that it's feasible to
      access attributes of `foo`, like self.val in this case.
  
      This function first parses fn.qual_name, "Foo.bar.<locals>.fn", and finds the
      closure whose class name appear in fn.qual_name first.
      """
      assert hasattr(fn, "__closure__")
      qual_name = fn.__qualname__.split(".")
      # Search from the right to left
      qual_name = qual_name[::-1]
  
      if fn.__closure__:
          for cls_name in qual_name:
              for cell in fn.__closure__:
                  try:
                      closure = cell.cell_contents
                  except ValueError:
                      # Continue when cell is empty and its content is unavailable
                      continue
                  if inspect.isclass(type(closure)):
                      if type(closure).__name__ == cls_name:
                          obj = closure
                          return obj
  
      return None
  
file_path: tensorflow-upstream/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 3 for calling a global function with example usage: _get_self_obj_from_closure(fn) and returns: None, obj