add_get#

module wntr.utils.enumtools

add_get(cls=None, *, prefix=None, abbrev=False, allow_none=True)[source]#

Decorator that will add a get() classmethod to an enum class.

Parameters:
  • prefix (str, optional) – A prefix to strip off any string values passed in, by default None

  • abbrev (bool, optional) – Allow truncating to the first character for checks, by default False

  • allow_none (bool, optional) – Allow None to be be passed through without raising error, by default True

Returns:

the modified class

Return type:

class

Notes

The get method behaves as follows:

For an integer, the integer value will be used to select the proper member. For an Enum object, the object’s name will be used, and it will be processed as a string. For a string, the method will:

  1. if allow_none is False, then raise a TypeError if the value is None, otherwise pass None back to calling function for processing

  2. capitalize the string

  3. remove leading or trailing spaces

  4. convert interior spaces or dashes to underscores

  5. optionally, remove a specified prefix from a string (using prefix, which

    should have a default assigned by the wntr.utils.enumtools.add_get() function.)

It will then try to get the member with the name corresponding to the converted string.

  1. optionally, if abbrev is True, then the string will be truncated to the first

    letter, only, after trying to use the full string as passed in. The abbrev parameter will have a default value based on how the add_get() decorator was called on this class.