code: def collect_targets(
      self,
      targets: Optional["TargetType"],
      *,
      onerror=None,
      **kwargs: Any,
  ) -> List["StageInfo"]:
      from dvc.exceptions import DvcException
      from dvc.repo.stage import StageInfo
      from dvc.utils.collections import ensure_list
  
      if not onerror:
  
          def onerror(_target, _exc):
              raise
  
      targets = ensure_list(targets)
      if not targets:
          return [StageInfo(stage) for stage in self.stages]
      targets_hash = self._hash_targets(targets, **kwargs)
      if targets_hash not in self._collected_targets:
          collected = []
          for target in targets:
              try:
                  collected.extend(
                      self.repo.stage.collect_granular(target, **kwargs)
                  )
              except DvcException as exc:
                  onerror(target, exc)
          self._collected_targets[targets_hash] = collected
  
      return self._collected_targets[targets_hash]
  
imports: import logging
  import time
  from collections import defaultdict
  from functools import partial
  from itertools import chain
  from typing import TYPE_CHECKING, Any, Callable, Dict, Iterable, Iterator, List, NamedTuple, Optional, Set, Tuple, Union
  from funcy.debug import format_time
  from dvc.dependency import ParamsDependency
  from dvc.fs import LocalFileSystem
  from dvc.fs.callbacks import DEFAULT_CALLBACK
  from dvc.log import logger
  from dvc.utils.objects import cached_property
label_desc: Use image node_id 26 for calling the Index obj's underlying member method code with example usage: obj.collect_targets(targets) and returns: self, unknown