33init. Note the use of a single dictionary instead of multiple conditions
44"""
55
6- __author__ = "Ibrahim Diop <ibrahim@sikilabs.com>"
7-
6+ from __future__ import annotations
7+ from typing import Callable , Dict , Any
88
9- from typing import Callable , Dict
9+ __author__ = "Ibrahim Diop <ibrahim@sikilabs.com>"
1010
1111
1212class Catalog :
@@ -20,7 +20,7 @@ def __init__(self, param: str) -> None:
2020 # dictionary that will be used to determine which static method is
2121 # to be executed but that will be also used to store possible param
2222 # value
23- self ._static_method_choices : Dict [ Callable ] = {
23+ self ._static_method_choices = {
2424 "param_value_1" : self ._static_method_1 ,
2525 "param_value_2" : self ._static_method_2 ,
2626 }
@@ -105,10 +105,10 @@ def _class_method_1(cls) -> None:
105105 print (f"Value { cls .x1 } " )
106106
107107 @classmethod
108- def _class_method_2 (cls )-> None :
108+ def _class_method_2 (cls ) -> None :
109109 print (f"Value { cls .x2 } " )
110110
111- _class_method_choices : Dict [ Callable ] = {
111+ _class_method_choices = {
112112 "param_value_1" : _class_method_1 ,
113113 "param_value_2" : _class_method_2 ,
114114 }
@@ -143,16 +143,17 @@ def _static_method_1() -> None:
143143 def _static_method_2 () -> None :
144144 print ("executed method 2!" )
145145
146- _static_method_choices : Dict [ Callable ] = {
146+ _static_method_choices = {
147147 "param_value_1" : _static_method_1 ,
148148 "param_value_2" : _static_method_2 ,
149149 }
150150
151- def main_method (self ):
151+ def main_method (self ) -> None :
152152 """will execute either _static_method_1 or _static_method_2
153153
154154 depending on self.param value
155155 """
156+
156157 self ._static_method_choices [self .param ].__get__ (None , self .__class__ )()
157158
158159
0 commit comments