I'm trying translate some code from python 2 to python 3 and had trouble with this code:
from enum import Enum, EnumMeta
class KeyCode(Enum):
A = 1
B = 2
C = 3
class KeyMeta(EnumMeta):
def __new__(mcs, name, bases, dct):
dct.update({e.name: e.value for e in KeyCode})
return super(KeyMeta, mcs).__new__(mcs, name, bases, dct)
class Key(Enum, metaclass=KeyMeta):
pass
print(repr(Key.A))
The problem is that for python2 Key.A
is enum < Key.A: 1>
, whereas for python3 it is < class 'int'>
.