parameters: (name, values)
return_statement: return enum
docstring: Helper function to create a "String" Enum.
  
      :param name: Name of the Enum being created. The module calling this function
          should not have any other member with the same name (because this function
          will add the created Enum as a member under that name).
      :param values: Values the Enum can take, either as a list of strings, or a
          single string with values separated by whitespaces or commas.
      :return: The corresponding Enum class.
  
      The motivation for using this helper function vs instantiating `_StrEnum`
      directly is that this function also registers the created Enum within the
      calling module. This makes it possible to pickle / unpickle this Enum as
      long as it is created at import time. The typical use case is within
      structured configs, as follows:
  
          @dataclass
          class MyConfig:
              color: StrEnum("Color", "red, green, blue") = "blue"
  
      Such a config (after being processed through Hydra / OmegaConf) may be used
      with string comparisons:
  
          if cfg.color == "red":
              ...
          elif cfg.color == "green":
              ...
          ...
  
      NB: a function is used instead of adding this logic to `_StrEnum.__init__()`
      because it turns out to be tricky to override an Enum constructor.
docstring_summary: Helper function to create a "String" Enum.
docstring_tokens: Helper function to create a String Enum .
function: def StrEnum(name, values):
      """
      Helper function to create a "String" Enum.
  
      :param name: Name of the Enum being created. The module calling this function
          should not have any other member with the same name (because this function
          will add the created Enum as a member under that name).
      :param values: Values the Enum can take, either as a list of strings, or a
          single string with values separated by whitespaces or commas.
      :return: The corresponding Enum class.
  
      The motivation for using this helper function vs instantiating `_StrEnum`
      directly is that this function also registers the created Enum within the
      calling module. This makes it possible to pickle / unpickle this Enum as
      long as it is created at import time. The typical use case is within
      structured configs, as follows:
  
          @dataclass
          class MyConfig:
              color: StrEnum("Color", "red, green, blue") = "blue"
  
      Such a config (after being processed through Hydra / OmegaConf) may be used
      with string comparisons:
  
          if cfg.color == "red":
              ...
          elif cfg.color == "green":
              ...
          ...
  
      NB: a function is used instead of adding this logic to `_StrEnum.__init__()`
      because it turns out to be tricky to override an Enum constructor.
      """
      enum = _StrEnum(name, values)
      # Obtain the module this function was called from.
      stack = inspect.stack()[1]
      src_module = inspect.getmodule(stack[0])
      # Add the generated Enum as member of this module.
      assert not hasattr(
          src_module, name
      ), f"module {src_module} already has a member '{name}'"
      setattr(src_module, name, enum)
      # We also need to set the Enum's module accordingly. As a result the unpickling
      # sequence of an instance of this Enum will be as follows:
      #   1. Identify this Enum's module as `src_module`
      #   2. Import `src_module`
      #   3. During import, this function (= `StrEnum()`) is called
      #   4. During this call, the Enum class is created and registered into `src_module`
      #   5. Once `src_module` is imported, the Enum class is obtained from it and the
      #      Enum instance can be created
      enum.__module__ = src_module.__name__
      return enum
function_tokens: def StrEnum ( name , values ) : enum = _StrEnum ( name , values ) # Obtain the module this function was called from. stack = inspect . stack ( ) [ 1 ] src_module = inspect . getmodule ( stack [ 0 ] ) # Add the generated Enum as member of this module. assert not hasattr ( src_module , name ) , f"module {src_module} already has a member '{name}'" setattr ( src_module , name , enum ) # We also need to set the Enum's module accordingly. As a result the unpickling # sequence of an instance of this Enum will be as follows: #   1. Identify this Enum's module as `src_module` #   2. Import `src_module` #   3. During import, this function (= `StrEnum()`) is called #   4. During this call, the Enum class is created and registered into `src_module` #   5. Once `src_module` is imported, the Enum class is obtained from it and the #      Enum instance can be created enum . __module__ = src_module . __name__ return enum