3
3
init. Note the use of a single dictionary instead of multiple conditions
4
4
"""
5
5
6
- __author__ = "Ibrahim Diop <[email protected] >"
7
-
6
+ from __future__ import annotations
7
+ from typing import Callable , Dict , Any
8
8
9
- from typing import Callable , Dict
9
+ __author__ = "Ibrahim Diop <[email protected] >"
10
10
11
11
12
12
class Catalog :
@@ -20,7 +20,7 @@ def __init__(self, param: str) -> None:
20
20
# dictionary that will be used to determine which static method is
21
21
# to be executed but that will be also used to store possible param
22
22
# value
23
- self ._static_method_choices : Dict [ Callable ] = {
23
+ self ._static_method_choices = {
24
24
"param_value_1" : self ._static_method_1 ,
25
25
"param_value_2" : self ._static_method_2 ,
26
26
}
@@ -105,10 +105,10 @@ def _class_method_1(cls) -> None:
105
105
print (f"Value { cls .x1 } " )
106
106
107
107
@classmethod
108
- def _class_method_2 (cls )-> None :
108
+ def _class_method_2 (cls ) -> None :
109
109
print (f"Value { cls .x2 } " )
110
110
111
- _class_method_choices : Dict [ Callable ] = {
111
+ _class_method_choices = {
112
112
"param_value_1" : _class_method_1 ,
113
113
"param_value_2" : _class_method_2 ,
114
114
}
@@ -143,16 +143,17 @@ def _static_method_1() -> None:
143
143
def _static_method_2 () -> None :
144
144
print ("executed method 2!" )
145
145
146
- _static_method_choices : Dict [ Callable ] = {
146
+ _static_method_choices = {
147
147
"param_value_1" : _static_method_1 ,
148
148
"param_value_2" : _static_method_2 ,
149
149
}
150
150
151
- def main_method (self ):
151
+ def main_method (self ) -> None :
152
152
"""will execute either _static_method_1 or _static_method_2
153
153
154
154
depending on self.param value
155
155
"""
156
+
156
157
self ._static_method_choices [self .param ].__get__ (None , self .__class__ )()
157
158
158
159
0 commit comments