code: def base_ctx(ctx):
      
  
      result = None
  
      if isclass(ctx):
          result = getattr(ctx, '__base__', None)
          if result is None:
              mro = getmro(ctx)
              if len(mro) > 1:
                  result = mro[1]
      else:
          result = ctx.__class__
  
      return result
docs: Get base ctx.
  
      :param ctx: initial ctx.
      :return: base ctx.