Skip to content

Commit 4ba0c3f

Browse files
committed
Added typehint to catalog pattern
1 parent 19ca1a9 commit 4ba0c3f

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

patterns/behavioral/catalog.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
init. Note the use of a single dictionary instead of multiple conditions
44
"""
55

6-
__author__ = "Ibrahim Diop <[email protected]>"
7-
6+
from __future__ import annotations
7+
from typing import Callable, Dict, Any
88

9-
from typing import Callable, Dict
9+
__author__ = "Ibrahim Diop <[email protected]>"
1010

1111

1212
class 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

Comments
 (0)