docs: def _check_format(format_str):
      """Check if `format_str` is valid and return format ID."""
      if not isinstance(format_str, (_unicode, str)):
          raise TypeError("Invalid format: {0!r}".format(format_str))
      try:
          format_int = _formats[format_str.upper()]
      except KeyError:
          raise ValueError("Unknown format: {0!r}".format(format_str))
      return format_int