File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import enum
2+
3+ CACHE_CODE_TO_CATEGORY : dict = {}
4+
5+
6+ class Category (enum .Enum ):
7+ HISTORY = {
8+ 'code' : 10001 ,
9+ 'name' : 'history' ,
10+ }
11+ MATH = {
12+ 'code' : 10002 ,
13+ 'name' : 'math' ,
14+ }
15+ PHYSICS = {
16+ 'code' : 10003 ,
17+ 'name' : 'physics' ,
18+ }
19+
20+ def __init__ (self , value : dict ):
21+ self .code = value ['code' ]
22+ self .category_name = value ['name' ]
23+ CACHE_CODE_TO_CATEGORY [self .code ] = self
24+
25+ @classmethod
26+ def get_by_code (cls , code : int ):
27+ return CACHE_CODE_TO_CATEGORY .get (code )
28+
29+
30+ if __name__ == '__main__' :
31+ print (Category .get_by_code (10001 ))
32+ print (Category .get_by_code (10002 ))
33+
Original file line number Diff line number Diff line change @@ -14,3 +14,6 @@ class BugStatus(enum.IntEnum):
1414print ('Ordered by value: ' )
1515print ('\n ' .join (' ' + s .name for s in sorted (BugStatus )))
1616
17+ print (BugStatus .new == 7 )
18+ print (BugStatus .incomplete == 6 )
19+
You can’t perform that action at this time.
0 commit comments