Skip to content

Commit bbc6643

Browse files
committed
ch25: changed MicroEnum to use __class_getitem__
1 parent c6a1da4 commit bbc6643

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

25-class-metaprog/tinyenums/microenum.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,10 @@ class MicroEnumMeta(type):
5454
def __prepare__(name, bases, **kwargs):
5555
return AutoFillDict()
5656

57-
def __getitem__(cls, key):
57+
58+
class MicroEnum(metaclass=MicroEnumMeta):
59+
def __class_getitem__(cls, key):
5860
for k, v in cls.__dict__.items():
5961
if v == key:
6062
return k
6163
raise KeyError(key)
62-
63-
64-
class MicroEnum(metaclass=MicroEnumMeta):
65-
pass

25-class-metaprog/tinyenums/nanoenum.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626

2727
class KeyIsValueDict(dict):
28-
2928
def __missing__(self, key):
3029
if key.startswith('__') and key.endswith('__'):
3130
raise KeyError(key)

0 commit comments

Comments
 (0)