66from abc import ABC , abstractmethod
77from inspect import signature
88from sys import argv
9+ from typing import Any
910
1011
1112class Model (ABC ):
1213 """The Model is the data layer of the application."""
1314 @abstractmethod
14- def __iter__ (self ):
15+ def __iter__ (self ) -> Any :
1516 pass
1617
1718 @abstractmethod
@@ -43,7 +44,7 @@ def __str__(self) -> str:
4344
4445 item_type = "product"
4546
46- def __iter__ (self ):
47+ def __iter__ (self ) -> Any :
4748 yield from self .products
4849
4950 def get (self , product : str ) -> dict :
@@ -56,7 +57,7 @@ def get(self, product: str) -> dict:
5657class View (ABC ):
5758 """The View is the presentation layer of the application."""
5859 @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 :
6061 pass
6162
6263 @abstractmethod
@@ -72,7 +73,7 @@ def item_not_found(self, item_type: str, item_name: str) -> None:
7273
7374class ConsoleView (View ):
7475 """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 :
7677 print (item_type .upper () + " LIST:" )
7778 for item in item_list :
7879 print (item )
@@ -112,13 +113,12 @@ def show_item_information(self, item_name: str) -> None:
112113 Show information about a {item_type} item.
113114 :param str item_name: the name of the {item_type} item to show information about
114115 """
116+ item_type : str = self .model .item_type
115117 try :
116- item_info : str = self .model .get (item_name )
118+ item_info : dict = self .model .get (item_name )
117119 except Exception :
118- item_type : str = self .model .item_type
119120 self .view .item_not_found (item_type , item_name )
120121 else :
121- item_type : str = self .model .item_type
122122 self .view .show_item_information (item_type , item_name , item_info )
123123
124124
@@ -127,7 +127,12 @@ class Router:
127127 def __init__ (self ):
128128 self .routes = {}
129129
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 :
131136 model_instance : Model = model_class ()
132137 view_instance : View = view_class ()
133138 self .routes [path ] = controller_class (model_instance , view_instance )
0 commit comments