code: def formatted(text, *args, **kwargs):
      
      if not text or "{" not in text:
          return text
      strict = kwargs.pop("strict", True)
      max_depth = kwargs.pop("max_depth", 3)
      objects = list(args) + [kwargs] if kwargs else args[0] if len(args) == 1 else args
      if not objects:
          return text
      definitions = {}
      markers = RE_FORMAT_MARKERS.findall(text)
      while markers:
          key = markers.pop()
          if key in definitions:
              continue
          val = _find_value(key, objects)
          if strict and val is None:
              return None
          val = str(val) if val is not None else "{%s}" % key
          markers.extend(m for m in RE_FORMAT_MARKERS.findall(val) if m not in definitions)
          definitions[key] = val
      if not max_depth or not isinstance(max_depth, int) or max_depth <= 0:
          return text
      expanded = dict((k, _rformat(k, v, definitions, max_depth)) for k, v in definitions.items())
      return text.format(**expanded)
docs: Args:
          text (str | unicode): Text to format
          *args: Objects to extract values from (as attributes)
          **kwargs: Optional values provided as named args
  
      Returns:
          (str): Attributes from this class are expanded if mentioned