ch25: changed MicroEnum to use __class_getitem__
This commit is contained in:
parent
c6a1da4882
commit
bbc664308a
@ -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
|
||||
|
@ -25,7 +25,6 @@ Testing ``KeyIsValueDict``::
|
||||
|
||||
|
||||
class KeyIsValueDict(dict):
|
||||
|
||||
def __missing__(self, key):
|
||||
if key.startswith('__') and key.endswith('__'):
|
||||
raise KeyError(key)
|
||||
|
Loading…
Reference in New Issue
Block a user