code: def import_object_with_scope(name):
    
  
    # Import modules until we can no longer import them. Prefer existing
    # attributes over importing modules at each step.
    parts = name.split('.')
    current_name = parts[0]
    obj = import_module(current_name)
    scope = None
    for part in parts[1:]:
      current_name += '.' + part
      try:
        if hasattr(obj, '__dict__'):
          # Using directly __dict__ for descriptors, where we want to get the descriptor's instance
          # and not calling the descriptor's __get__ method.
          sub_obj = obj.__dict__[part]
        else:
          sub_obj = getattr(obj, part)
  
        scope, obj = obj, sub_obj
      except (AttributeError, KeyError):
        try:
          obj = scope = import_module(current_name)
        except ImportError as exc:
          if 'named {}'.format(part) in str(exc):
            raise ImportError(current_name)
          raise
    return obj, scope
docs: Imports a Python object by an absolute identifier.
  
    # Arguments
    name (str): The name of the Python object to import.
  
    # Returns
    (any, Module): The object and the module that contains it. Note that
      for plain modules loaded with this function, both elements of the
      tuple may be the same object.