@@ -12,28 +12,31 @@ class Catalog:
12
12
parameter
13
13
"""
14
14
15
- def __init__ (self , param ) :
15
+ def __init__ (self , param : str ) -> None :
16
16
17
17
# dictionary that will be used to determine which static method is
18
18
# to be executed but that will be also used to store possible param
19
19
# value
20
- self ._static_method_choices = {'param_value_1' : self ._static_method_1 , 'param_value_2' : self ._static_method_2 }
20
+ self ._static_method_choices = {
21
+ "param_value_1" : self ._static_method_1 ,
22
+ "param_value_2" : self ._static_method_2 ,
23
+ }
21
24
22
25
# simple test to validate param value
23
26
if param in self ._static_method_choices .keys ():
24
27
self .param = param
25
28
else :
26
- raise ValueError ("Invalid Value for Param: {0}" . format ( param ) )
29
+ raise ValueError (f "Invalid Value for Param: { param } " )
27
30
28
31
@staticmethod
29
- def _static_method_1 ():
32
+ def _static_method_1 () -> None :
30
33
print ("executed method 1!" )
31
34
32
35
@staticmethod
33
- def _static_method_2 ():
36
+ def _static_method_2 () -> None :
34
37
print ("executed method 2!" )
35
38
36
- def main_method (self ):
39
+ def main_method (self ) -> None :
37
40
"""will execute either _static_method_1 or _static_method_2
38
41
39
42
depending on self.param value
@@ -49,24 +52,27 @@ class CatalogInstance:
49
52
parameter
50
53
"""
51
54
52
- def __init__ (self , param ) :
53
- self .x1 = 'x1'
54
- self .x2 = 'x2'
55
+ def __init__ (self , param : str ) -> None :
56
+ self .x1 = "x1"
57
+ self .x2 = "x2"
55
58
# simple test to validate param value
56
59
if param in self ._instance_method_choices :
57
60
self .param = param
58
61
else :
59
- raise ValueError ("Invalid Value for Param: {0}" . format ( param ) )
62
+ raise ValueError (f "Invalid Value for Param: { param } " )
60
63
61
- def _instance_method_1 (self ):
62
- print ("Value {}" . format ( self .x1 ) )
64
+ def _instance_method_1 (self ) -> None :
65
+ print (f "Value { self .x1 } " )
63
66
64
- def _instance_method_2 (self ):
65
- print ("Value {}" . format ( self .x2 ) )
67
+ def _instance_method_2 (self ) -> None :
68
+ print (f "Value { self .x2 } " )
66
69
67
- _instance_method_choices = {'param_value_1' : _instance_method_1 , 'param_value_2' : _instance_method_2 }
70
+ _instance_method_choices = {
71
+ "param_value_1" : _instance_method_1 ,
72
+ "param_value_2" : _instance_method_2 ,
73
+ }
68
74
69
- def main_method (self ):
75
+ def main_method (self ) -> None :
70
76
"""will execute either _instance_method_1 or _instance_method_2
71
77
72
78
depending on self.param value
@@ -81,25 +87,28 @@ class CatalogClass:
81
87
parameter
82
88
"""
83
89
84
- x1 = 'x1'
85
- x2 = 'x2'
90
+ x1 = "x1"
91
+ x2 = "x2"
86
92
87
- def __init__ (self , param ) :
93
+ def __init__ (self , param : str ) -> None :
88
94
# simple test to validate param value
89
95
if param in self ._class_method_choices :
90
96
self .param = param
91
97
else :
92
- raise ValueError ("Invalid Value for Param: {0}" . format ( param ) )
98
+ raise ValueError (f "Invalid Value for Param: { param } " )
93
99
94
100
@classmethod
95
- def _class_method_1 (cls ):
96
- print ("Value {}" . format ( cls .x1 ) )
101
+ def _class_method_1 (cls ) -> None :
102
+ print (f "Value { cls .x1 } " )
97
103
98
104
@classmethod
99
- def _class_method_2 (cls ):
100
- print ("Value {}" . format ( cls .x2 ) )
105
+ def _class_method_2 (cls ) -> None :
106
+ print (f "Value { cls .x2 } " )
101
107
102
- _class_method_choices = {'param_value_1' : _class_method_1 , 'param_value_2' : _class_method_2 }
108
+ _class_method_choices = {
109
+ "param_value_1" : _class_method_1 ,
110
+ "param_value_2" : _class_method_2 ,
111
+ }
103
112
104
113
def main_method (self ):
105
114
"""will execute either _class_method_1 or _class_method_2
@@ -116,28 +125,32 @@ class CatalogStatic:
116
125
parameter
117
126
"""
118
127
119
- def __init__ (self , param ) :
128
+ def __init__ (self , param : str ) -> None :
120
129
# simple test to validate param value
121
130
if param in self ._static_method_choices :
122
131
self .param = param
123
132
else :
124
- raise ValueError ("Invalid Value for Param: {0}" . format ( param ) )
133
+ raise ValueError (f "Invalid Value for Param: { param } " )
125
134
126
135
@staticmethod
127
- def _static_method_1 ():
136
+ def _static_method_1 () -> None :
128
137
print ("executed method 1!" )
129
138
130
139
@staticmethod
131
- def _static_method_2 ():
140
+ def _static_method_2 () -> None :
132
141
print ("executed method 2!" )
133
142
134
- _static_method_choices = {'param_value_1' : _static_method_1 , 'param_value_2' : _static_method_2 }
143
+ _static_method_choices = {
144
+ "param_value_1" : _static_method_1 ,
145
+ "param_value_2" : _static_method_2 ,
146
+ }
135
147
136
- def main_method (self ):
148
+ def main_method (self ) -> None :
137
149
"""will execute either _static_method_1 or _static_method_2
138
150
139
151
depending on self.param value
140
152
"""
153
+
141
154
self ._static_method_choices [self .param ].__get__ (None , self .__class__ )()
142
155
143
156
@@ -163,4 +176,5 @@ def main():
163
176
164
177
if __name__ == "__main__" :
165
178
import doctest
179
+
166
180
doctest .testmod ()
0 commit comments