code: def _parse_key(flat_key: str):
      if not isinstance(flat_key, string_type):
          raise TypeError("keys must be strings")
  
      split_key = _dot_or_indexes_re.split(flat_key)
      parts: list[t.Any] = [""] if flat_key.startswith(".") else []
  
      for i in range(0, len(split_key), 5):
          sep = split_key[i]
  
          if sep != "":
              raise ValueError(
                  "invalid separator %r in key %r" % (sep, flat_key)
              )
  
          if len(split_key) < i + 4:
              break
  
          if split_key[i + 1] is not None:
              # quoted first string
              string = split_key[i + 1]
              if len(string) == 2:
                  string = ""
              elif i == 0:
                  string = (
                      string[2:-1]
                      if string.startswith(".")
                      else string[1:-1]
                  )
              else:
                  if string[0] != ".":
                      raise ValueError(
                          "invalid string %r in key %r"
                          % (string, flat_key)
                      )
                  string = string[2:-1]
              parts.append(string)
  
          elif split_key[i + 2] is not None:
              # index
              parts.append(int(split_key[i + 2][1:-1]))
  
          elif (
              split_key[i + 3] is not None
              or split_key[i + 4] is not None
          ):
              # unquoted string
              string = split_key[i + 3] or split_key[i + 4] or ""
              if len(string) == 0:
                  string = ""
              elif i == 0:
                  string = (
                      string[1:] if string.startswith(".") else string
                  )
              else:
                  if string[0] != ".":
                      raise ValueError(
                          "invalid string %r in key %r"
                          % (string, flat_key)
                      )
                  string = string[1:]
              parts.append(string)
          else:
              assert False
  
      if len(parts) > 0 and isinstance(parts[0], int):
          parts.insert(0, "")
      return parts
  
imports: from __future__ import absolute_import
  from __future__ import annotations
  import re
  import sys
  import typing
  from operator import itemgetter
label_desc: Use image node_id 3 for calling a global function with example usage: _parse_key(flat_key) and returns: parts