code: def find_ctx(elt):
      
  
      result = elt  # by default, result is ctx
  
      # if elt is ctx and elt is a method, it is possible to find the best ctx
      if ismethod(elt):
          # get instance and class of the elt
          instance = get_method_self(elt)
          # if instance is not None, the right context is the instance
          if instance is not None:
              result = instance
  
          elif PY2:
              result = elt.im_class
  
      return result
docs: Get the right ctx related to input elt.
  
      In order to keep safe memory as much as possible, it is important to find
      the right context element. For example, instead of putting properties on
      a function at the level of an instance, it is important to save such
      property on the instance because the function.__dict__ is shared with
      instance class function, and so, if the instance is deleted from memory,
      the property is still present in the class memory. And so on, it is
      impossible to identify the right context in such case if all properties
      are saved with the same key in the same function which is the function.