6
6
from abc import ABC , abstractmethod
7
7
from inspect import signature
8
8
from sys import argv
9
+ from typing import Any
9
10
10
11
11
12
class Model (ABC ):
12
13
"""The Model is the data layer of the application."""
13
14
@abstractmethod
14
- def __iter__ (self ):
15
+ def __iter__ (self ) -> Any :
15
16
pass
16
17
17
18
@abstractmethod
@@ -43,7 +44,7 @@ def __str__(self) -> str:
43
44
44
45
item_type = "product"
45
46
46
- def __iter__ (self ):
47
+ def __iter__ (self ) -> Any :
47
48
yield from self .products
48
49
49
50
def get (self , product : str ) -> dict :
@@ -56,7 +57,7 @@ def get(self, product: str) -> dict:
56
57
class View (ABC ):
57
58
"""The View is the presentation layer of the application."""
58
59
@abstractmethod
59
- def show_item_list (self , item_type : str , item_list : dict ) -> None :
60
+ def show_item_list (self , item_type : str , item_list : list ) -> None :
60
61
pass
61
62
62
63
@abstractmethod
@@ -72,7 +73,7 @@ def item_not_found(self, item_type: str, item_name: str) -> None:
72
73
73
74
class ConsoleView (View ):
74
75
"""The View is the presentation layer of the application."""
75
- def show_item_list (self , item_type : str , item_list : dict ) -> None :
76
+ def show_item_list (self , item_type : str , item_list : list ) -> None :
76
77
print (item_type .upper () + " LIST:" )
77
78
for item in item_list :
78
79
print (item )
@@ -112,13 +113,12 @@ def show_item_information(self, item_name: str) -> None:
112
113
Show information about a {item_type} item.
113
114
:param str item_name: the name of the {item_type} item to show information about
114
115
"""
116
+ item_type : str = self .model .item_type
115
117
try :
116
- item_info : str = self .model .get (item_name )
118
+ item_info : dict = self .model .get (item_name )
117
119
except Exception :
118
- item_type : str = self .model .item_type
119
120
self .view .item_not_found (item_type , item_name )
120
121
else :
121
- item_type : str = self .model .item_type
122
122
self .view .show_item_information (item_type , item_name , item_info )
123
123
124
124
@@ -127,7 +127,12 @@ class Router:
127
127
def __init__ (self ):
128
128
self .routes = {}
129
129
130
- def register (self , path : str , controller_class : Controller , model_class : Model , view_class : View ) -> None :
130
+ def register (
131
+ self ,
132
+ path : str ,
133
+ controller_class : type [Controller ],
134
+ model_class : type [Model ],
135
+ view_class : type [View ]) -> None :
131
136
model_instance : Model = model_class ()
132
137
view_instance : View = view_class ()
133
138
self .routes [path ] = controller_class (model_instance , view_instance )
0 commit comments