code: def get_intermediate_dirs(fs, dir_path):
      # type: (FS, Text) -> List[Text]
      
      intermediates = []
      with fs.lock():
          for path in recursepath(abspath(dir_path), reverse=True):
              try:
                  resource = fs.getinfo(path)
              except ResourceNotFound:
                  intermediates.append(abspath(path))
              else:
                  if resource.is_dir:
                      break
                  raise errors.DirectoryExpected(dir_path)
      return intermediates[::-1][:-1]
docs: Get a list of non-existing intermediate directories.
  
      Arguments:
          fs (FS): A filesystem instance.
          dir_path (str): A path to a new directory on the filesystem.
  
      Returns:
          list: A list of non-existing paths.
  
      Raises:
          ~fs.errors.DirectoryExpected: If a path component
              references a file and not a directory.