parameters: (key: Union[Keys, str])
return_statement: return key
docstring: Replace key by alias and verify whether it's a valid one.
docstring_summary: Replace key by alias and verify whether it's a valid one.
docstring_tokens: Replace key by alias and verify whether it s a valid one .
function: def _parse_key(key: Union[Keys, str]) -> Union[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("Invalid key: %s" % (key,))
  
      return key
function_tokens: def _parse_key ( key : Union [ Keys , str ] ) -> Union [ str , Keys ] : # 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 ( "Invalid key: %s" % ( key , ) ) return key