StringIntEnum

class brainsets.core.StringIntEnum(value)[source]

Bases: Enum

Base class for string-integer enums.

This class extends Python’s built-in Enum class to provide:
  • String representation via __str__

  • Integer representation via __int__

  • Case-insensitive string parsing via from_string()

  • Maximum value lookup via max_value()

>>> class Color(StringIntEnum):
...     RED = 1
...     BLUE = 2
>>> str(Color.RED)
'RED'
>>> int(Color.RED)
1
>>> Color.from_string("red")
<Color.RED: 1>
>>> Color.max_value()
2
classmethod from_string(string)[source]

Convert a string to an enum member. This method is case insensitive and will replace spaces with underscores.

Parameters:

string (str) – The string to convert to an enum member.

Return type:

StringIntEnum

Examples

>>> from brainsets.taxonomy import Sex
>>> Sex.from_string("Male")
<Sex.MALE: 1>
>>> Sex.from_string("M")
<Sex.MALE: 1>
classmethod max_value()[source]

Return the maximum value in the enum class.