ch25: changed MicroEnum to use __class_getitem__

This commit is contained in:
Luciano Ramalho 2021-04-08 14:43:15 -03:00
parent c6a1da4882
commit bbc664308a
2 changed files with 3 additions and 6 deletions

View File

@ -54,12 +54,10 @@ class MicroEnumMeta(type):
def __prepare__(name, bases, **kwargs):
return AutoFillDict()
def __getitem__(cls, key):
class MicroEnum(metaclass=MicroEnumMeta):
def __class_getitem__(cls, key):
for k, v in cls.__dict__.items():
if v == key:
return k
raise KeyError(key)
class MicroEnum(metaclass=MicroEnumMeta):
pass

View File

@ -25,7 +25,6 @@ Testing ``KeyIsValueDict``::
class KeyIsValueDict(dict):
def __missing__(self, key):
if key.startswith('__') and key.endswith('__'):
raise KeyError(key)