code: def _parse_key(key: Keys | str) -> str | Keys:
      """
      Replace key by alias and verify whether it's a valid one.
      """
      # Already a parse key? -> Return it.
      if isinstance(key, Keys):
          return key
  
      # Lookup aliases.
      key = KEY_ALIASES.get(key, key)
  
      # Replace 'space' by ' '
      if key == "space":
          key = " "
  
      # Return as `Key` object when it's a special key.
      try:
          return Keys(key)
      except ValueError:
          pass
  
      # Final validation.
      if len(key) != 1:
          raise ValueError(f"Invalid key: {key}")
  
      return key
  
imports: from __future__ import annotations
  from abc import ABCMeta, abstractmethod, abstractproperty
  from inspect import isawaitable
  from typing import TYPE_CHECKING, Any, Callable, Coroutine, Hashable, Sequence, Tuple, TypeVar, Union, cast
  from prompt_toolkit.cache import SimpleCache
  from prompt_toolkit.filters import FilterOrBool, Never, to_filter
  from prompt_toolkit.keys import KEY_ALIASES, Keys
label_desc: Use image node_id 1 for calling a global function with example usage: _parse_key(key) and returns: key, key, Keys