I'm trying to find out whether two enum instances represent the same item of an enum class. Imagine the following simple program which works as expected:
from enum import Enum, auto
class myEnum(Enum):
ITEM1 = auto()
ITEM2 = auto()
enum1 = myEnum.ITEM1
enum2 = myEnum.ITEM2
enum3 = myEnum.ITEM1
print(enum1 == enum2)
print(enum1 == enum3)
print(enum1 == myEnum.ITEM1)
print(enum1 == myEnum.ITEM2)
Output:
False
True
True
False
My real application is slightly more complicated with creation of enum instances at different places, but all of the same class defined in a single module. Here the result is not as expected, even if the instances reflect the same value:
itype
<InstrumentTypes.FIXEDPOINTCELL: 5>
type(itype)
<enum 'InstrumentTypes'>
a
<InstrumentTypes.FIXEDPOINTCELL: 5>
type(a)
<enum 'InstrumentTypes'>
a == itype
False
Regarding the comments below it doesn't seem to be an enum-specific issue but a problem about multiple imports of the same module at different places. I'll try to clean up in the overall structure to get consistent imports.