code: def _list_dir(dir, filters=None, ext=None, incomplete=None):
      """Python based directory listing for completions.
  
      Returns a list of paths for `dir` to include in completion
      results.
  
      We use shell functions (e.g. compgen on bash) where possible to
      provide listing. This is for the sake of speed as well as making
      the behavior as close as possible to the user's native
      shell. However, supporting new shells means implementing behavior
      for our !! directives. We provide native Python implementation as
      a fallback where we have not yet implemented handling for our
      directives.
  
      `filters` is a None or a list of functions used to filter (select
      for inclusion) paths by returning True. Each function must accept
      a single argument, which is a pathlib.Path object for the path
      being filtered.  All filters must return True for a path to be
      included in the result.
  
      `ext` is None or a list of file extensions, not including leading
      dots. If specified, a path is filtered (selected for inclusion) if
      its suffix matches any of the specified extensions. Matching in
      this case is case insensitive.
      """
      import pathlib
  
      ext = set(_normalize_file_extensions(ext))
  
      subdir_incomplete, path_incomplete = _split_path_incomplete(
          incomplete
      )
      root = pathlib.Path(dir, subdir_incomplete)
      if not os.path.isdir(root):
          return []
  
      results = set()
      for path in root.iterdir():
          if not _filter_path(path, filters, ext, path_incomplete):
              continue
          results.add(_format_path_for_list(path, dir))
      return _sort_list_dir_result(results)
  
imports: import os
label_desc: Use image node_id 3 for calling a global function with example usage: _list_dir(dir, filters, ext, incomplete) and returns: _sort_list_dir_result, list