88
99
1010class Catalog :
11- """catalog of multiple static methods that are executed depending on an init
12-
13- parameter
11+ """catalog of multiple static methods that are executed depending on an init parameter
1412 """
1513
1614def __init__ (self ,param :str )-> None :
@@ -30,25 +28,24 @@ def __init__(self, param: str) -> None:
3028raise ValueError (f"Invalid Value for Param:{ param } " )
3129
3230@staticmethod
33- def _static_method_1 ()-> None :
34- print ( "executed method 1!" )
31+ def _static_method_1 ()-> str :
32+ return "executed method 1!"
3533
3634@staticmethod
37- def _static_method_2 ()-> None :
38- print ( "executed method 2!" )
35+ def _static_method_2 ()-> str :
36+ return "executed method 2!"
3937
40- def main_method (self )-> None :
38+ def main_method (self )-> str :
4139"""will execute either _static_method_1 or _static_method_2
4240
4341 depending on self.param value
4442 """
45- self ._static_method_choices [self .param ]()
43+ return self ._static_method_choices [self .param ]()
4644
4745
4846# Alternative implementation for different levels of methods
4947class CatalogInstance :
5048"""catalog of multiple methods that are executed depending on an init
51-
5249 parameter
5350 """
5451
@@ -61,29 +58,28 @@ def __init__(self, param: str) -> None:
6158else :
6259raise ValueError (f"Invalid Value for Param:{ param } " )
6360
64- def _instance_method_1 (self )-> None :
65- print ( f"Value{ self .x1 } " )
61+ def _instance_method_1 (self )-> str :
62+ return f"Value{ self .x1 } "
6663
67- def _instance_method_2 (self )-> None :
68- print ( f"Value{ self .x2 } " )
64+ def _instance_method_2 (self )-> str :
65+ return f"Value{ self .x2 } "
6966
7067_instance_method_choices = {
7168"param_value_1" :_instance_method_1 ,
7269"param_value_2" :_instance_method_2 ,
7370 }
7471
75- def main_method (self )-> None :
72+ def main_method (self )-> str :
7673"""will execute either _instance_method_1 or _instance_method_2
7774
7875 depending on self.param value
7976 """
80- self ._instance_method_choices [self .param ].__get__ (self )()# type: ignore
77+ return self ._instance_method_choices [self .param ].__get__ (self )()# type: ignore
8178# type ignore reason: https://github.com/python/mypy/issues/10206
8279
8380
8481class CatalogClass :
8582"""catalog of multiple class methods that are executed depending on an init
86-
8783 parameter
8884 """
8985
@@ -98,30 +94,29 @@ def __init__(self, param: str) -> None:
9894raise ValueError (f"Invalid Value for Param:{ param } " )
9995
10096@classmethod
101- def _class_method_1 (cls )-> None :
102- print ( f"Value{ cls .x1 } " )
97+ def _class_method_1 (cls )-> str :
98+ return f"Value{ cls .x1 } "
10399
104100@classmethod
105- def _class_method_2 (cls )-> None :
106- print ( f"Value{ cls .x2 } " )
101+ def _class_method_2 (cls )-> str :
102+ return f"Value{ cls .x2 } "
107103
108104_class_method_choices = {
109105"param_value_1" :_class_method_1 ,
110106"param_value_2" :_class_method_2 ,
111107 }
112108
113- def main_method (self ):
109+ def main_method (self )-> str :
114110"""will execute either _class_method_1 or _class_method_2
115111
116112 depending on self.param value
117113 """
118- self ._class_method_choices [self .param ].__get__ (None ,self .__class__ )()# type: ignore
114+ return self ._class_method_choices [self .param ].__get__ (None ,self .__class__ )()# type: ignore
119115# type ignore reason: https://github.com/python/mypy/issues/10206
120116
121117
122118class CatalogStatic :
123119"""catalog of multiple static methods that are executed depending on an init
124-
125120 parameter
126121 """
127122
@@ -133,45 +128,45 @@ def __init__(self, param: str) -> None:
133128raise ValueError (f"Invalid Value for Param:{ param } " )
134129
135130@staticmethod
136- def _static_method_1 ()-> None :
137- print ( "executed method 1!" )
131+ def _static_method_1 ()-> str :
132+ return "executed method 1!"
138133
139134@staticmethod
140- def _static_method_2 ()-> None :
141- print ( "executed method 2!" )
135+ def _static_method_2 ()-> str :
136+ return "executed method 2!"
142137
143138_static_method_choices = {
144139"param_value_1" :_static_method_1 ,
145140"param_value_2" :_static_method_2 ,
146141 }
147142
148- def main_method (self )-> None :
143+ def main_method (self )-> str :
149144"""will execute either _static_method_1 or _static_method_2
150145
151146 depending on self.param value
152147 """
153148
154- self ._static_method_choices [self .param ].__get__ (None ,self .__class__ )()# type: ignore
149+ return self ._static_method_choices [self .param ].__get__ (None ,self .__class__ )()# type: ignore
155150# type ignore reason: https://github.com/python/mypy/issues/10206
156151
157152
158153def main ():
159154"""
160155 >>> test = Catalog('param_value_2')
161156 >>> test.main_method()
162- executed method 2!
157+ ' executed method 2!'
163158
164159 >>> test = CatalogInstance('param_value_1')
165160 >>> test.main_method()
166- Value x1
161+ ' Value x1'
167162
168163 >>> test = CatalogClass('param_value_2')
169164 >>> test.main_method()
170- Value x2
165+ ' Value x2'
171166
172167 >>> test = CatalogStatic('param_value_1')
173168 >>> test.main_method()
174- executed method 1!
169+ ' executed method 1!'
175170 """
176171
177172