docstr: Collects a list of (stage, filter_info) from the given target.
  
  Priority is in the order of following in case of ambiguity:
  - .dvc file or .yaml file
  - dir if recursive and directory exists
  - foreach_group_name or stage_name
  - generated stage name from a foreach group
  - output file
  
  Args:
      target: if not provided, all of the stages without any filters are
          returned.
          If `target` is a path to a dvc-tracked output,
          a (stage, output_path) is returned.
          Otherwise, the details above for `target` in `collect()`
          applies.
  
      (see `collect()` for other arguments)
docstr_tok: ["Collects","a","list","of","(","stage",",","filter_info",")","from","the","given","target",".","Priority","is","in","the","order","of","following","in","case","of","ambiguity",":","-",".dvc","file","or",".yaml","file","-","dir","if","recursive","and","directory","exists","-","foreach_group_name","or","stage_name","-","generated","stage","name","from","a","foreach","group","-","output","file","Args",":","target",":","if","not","provided",",","all","of","the","stages","without","any","filters","are","returned",".","If","`","target","`","is","a","path","to","a","dvc-tracked","output",",","a","(","stage",",","output_path",")","is","returned",".","Otherwise",",","the","details","above","for","`","target","`","in","`","collect","(",")","`","applies",".","(","see","`","collect","(",")","`","for","other","arguments",")"]
code: def collect_granular(
      self,
      target: Optional[str] = None,
      with_deps: bool = False,
      recursive: bool = False,
      graph: Optional["DiGraph"] = None,
  ) -> List[StageInfo]:
      """Collects a list of (stage, filter_info) from the given target.
  
      Priority is in the order of following in case of ambiguity:
      - .dvc file or .yaml file
      - dir if recursive and directory exists
      - foreach_group_name or stage_name
      - generated stage name from a foreach group
      - output file
  
      Args:
          target: if not provided, all of the stages without any filters are
              returned.
              If `target` is a path to a dvc-tracked output,
              a (stage, output_path) is returned.
              Otherwise, the details above for `target` in `collect()`
              applies.
  
          (see `collect()` for other arguments)
      """
      if not target:
          return [StageInfo(stage) for stage in self.repo.index.stages]
  
      target = as_posix(target)
  
      stages, file, _ = _collect_specific_target(
          self, target, with_deps, recursive
      )
      if not stages:
          if not (recursive and self.fs.isdir(target)):
              try:
                  (out,) = self.repo.find_outs_by_path(
                      target, strict=False
                  )
                  return [StageInfo(out.stage, self.fs.abspath(target))]
              except OutputNotFoundError:
                  pass
  
          from dvc.dvcfile import is_valid_filename
          from dvc.stage.exceptions import (
              StageFileDoesNotExistError,
              StageNotFound,
          )
  
          try:
              stages = self.collect(
                  target,
                  with_deps,
                  recursive,
                  graph,
              )
          except StageFileDoesNotExistError as exc:
              # collect() might try to use `target` as a stage name
              # and throw error that dvc.yaml does not exist, whereas it
              # should say that both stage name and file does not exist.
              if file and is_valid_filename(file):
                  raise
              raise NoOutputOrStageError(target, exc.file) from exc
          except StageNotFound as exc:
              raise NoOutputOrStageError(target, exc.file) from exc
  
      return [StageInfo(stage) for stage in stages]
  
imports: import fnmatch
  import typing
  from contextlib import suppress
  from functools import wraps
  from typing import Iterable, List, NamedTuple, Optional, Set, Tuple, Union
  from dvc.exceptions import NoOutputOrStageError, OutputDuplicationError, OutputNotFoundError
  from dvc.log import logger
  from dvc.repo import lock_repo
  from dvc.ui import ui
  from dvc.utils import as_posix, parse_target
label_desc: Use image node_id 15 for calling the StageLoad obj's underlying member method code with example usage: obj.collect_granular(target, with_deps, recursive, graph) and returns: unknown, unknown, list