ExtendedEnumType

(class from pyomo.common.enums)

class pyomo.common.enums.ExtendedEnumType(cls, bases, classdict, **kwds)[source]

Bases: EnumType

Metaclass for creating an enum.Enum that extends another Enum

In general, enum.Enum classes are not extensible: that is, they are frozen when defined and cannot be the base class of another Enum. This Metaclass provides a workaround for creating a new Enum that extends an existing enum. Members in the base Enum are all present as members on the extended enum.

Example

class ObjectiveSense(enum.IntEnum):
    minimize = 1
    maximize = -1

class ProblemSense(enum.IntEnum, metaclass=ExtendedEnumType):
    __base_enum__ = ObjectiveSense

    unknown = 0
>>> list(ProblemSense)
[<ProblemSense.unknown: 0>, <ObjectiveSense.minimize: 1>, <ObjectiveSense.maximize: -1>]
>>> ProblemSense.unknown
<ProblemSense.unknown: 0>
>>> ProblemSense.maximize
<ObjectiveSense.maximize: -1>
>>> ProblemSense(0)
<ProblemSense.unknown: 0>
>>> ProblemSense(1)
<ObjectiveSense.minimize: 1>
>>> ProblemSense('unknown')
<ProblemSense.unknown: 0>
>>> ProblemSense('maximize')
<ObjectiveSense.maximize: -1>
>>> hasattr(ProblemSense, 'minimize')
True
>>> ProblemSense.minimize is ObjectiveSense.minimize
True
>>> ProblemSense.minimize in ProblemSense
True
__init__(*args, **kwargs)

Methods

__init__(*args, **kwargs)

mro()

Return a type's method resolution order.

Member Documentation

mro()

Return a type’s method resolution order.