@@ -14,14 +14,14 @@ def __iter__(self):
14
14
pass
15
15
16
16
@abstractmethod
17
- def get (self , item ) :
17
+ def get (self , item : str ) -> dict :
18
18
"""Returns an object with a .items() call method
19
19
that iterates over key,value pairs of its information."""
20
20
pass
21
21
22
22
@property
23
23
@abstractmethod
24
- def item_type (self ):
24
+ def item_type (self ) -> str :
25
25
pass
26
26
27
27
@@ -30,7 +30,7 @@ class Price(float):
30
30
"""A polymorphic way to pass a float with a particular
31
31
__str__ functionality."""
32
32
33
- def __str__ (self ):
33
+ def __str__ (self ) -> str :
34
34
return f"{ self :.2f} "
35
35
36
36
products = {
@@ -44,7 +44,7 @@ def __str__(self):
44
44
def __iter__ (self ):
45
45
yield from self .products
46
46
47
- def get (self , product ) :
47
+ def get (self , product : str ) -> dict :
48
48
try :
49
49
return self .products [product ]
50
50
except KeyError as e :
@@ -53,40 +53,40 @@ def get(self, product):
53
53
54
54
class View (ABC ):
55
55
@abstractmethod
56
- def show_item_list (self , item_type , item_list ) :
56
+ def show_item_list (self , item_type : str , item_list : dict ) -> None :
57
57
pass
58
58
59
59
@abstractmethod
60
- def show_item_information (self , item_type , item_name , item_info ) :
60
+ def show_item_information (self , item_type : str , item_name : str , item_info : str ) -> None :
61
61
"""Will look for item information by iterating over key,value pairs
62
62
yielded by item_info.items()"""
63
63
pass
64
64
65
65
@abstractmethod
66
- def item_not_found (self , item_type , item_name ):
66
+ def item_not_found (self , item_type , item_name ) -> None :
67
67
pass
68
68
69
69
70
70
class ConsoleView (View ):
71
- def show_item_list (self , item_type , item_list ):
71
+ def show_item_list (self , item_type , item_list ) -> None :
72
72
print (item_type .upper () + " LIST:" )
73
73
for item in item_list :
74
74
print (item )
75
75
print ("" )
76
76
77
77
@staticmethod
78
- def capitalizer (string ):
78
+ def capitalizer (string ) -> str :
79
79
return string [0 ].upper () + string [1 :].lower ()
80
80
81
- def show_item_information (self , item_type , item_name , item_info ):
81
+ def show_item_information (self , item_type , item_name , item_info ) -> None :
82
82
print (item_type .upper () + " INFORMATION:" )
83
83
printout = "Name: %s" % item_name
84
84
for key , value in item_info .items ():
85
85
printout += ", " + self .capitalizer (str (key )) + ": " + str (value )
86
86
printout += "\n "
87
87
print (printout )
88
88
89
- def item_not_found (self , item_type , item_name ):
89
+ def item_not_found (self , item_type , item_name ) -> None :
90
90
print (f'That { item_type } "{ item_name } " does not exist in the records' )
91
91
92
92
@@ -95,12 +95,12 @@ def __init__(self, model, view):
95
95
self .model = model
96
96
self .view = view
97
97
98
- def show_items (self ):
98
+ def show_items (self ) -> None :
99
99
items = list (self .model )
100
100
item_type = self .model .item_type
101
101
self .view .show_item_list (item_type , items )
102
102
103
- def show_item_information (self , item_name ):
103
+ def show_item_information (self , item_name ) -> None :
104
104
"""
105
105
Show information about a {item_type} item.
106
106
:param str item_name: the name of the {item_type} item to show information about
@@ -117,16 +117,16 @@ def show_item_information(self, item_name):
117
117
118
118
class Router :
119
119
def __init__ (self ):
120
- self .routes = {}
120
+ self .routes : dict = {}
121
121
122
- def register (self , path , controller , model , view ) :
123
- model = model ()
124
- view = view ()
122
+ def register (self , path : str , controller : object , model : object , view : object ) -> None :
123
+ model : object = model ()
124
+ view : object = view ()
125
125
self .routes [path ] = controller (model , view )
126
126
127
- def resolve (self , path ):
127
+ def resolve (self , path ) -> Controller :
128
128
if self .routes .get (path ):
129
- controller = self .routes [path ]
129
+ controller : object = self .routes [path ]
130
130
return controller
131
131
else :
132
132
return None
@@ -166,12 +166,12 @@ def main():
166
166
167
167
168
168
if __name__ == "__main__" :
169
- router = Router ()
169
+ router : object = Router ()
170
170
router .register ("products" , Controller , ProductModel , ConsoleView )
171
- controller = router .resolve (argv [1 ])
171
+ controller : object = router .resolve (argv [1 ])
172
172
173
- command = str (argv [2 ]) if len (argv ) > 2 else None
174
- args = ' ' .join (map (str , argv [3 :])) if len (argv ) > 3 else None
173
+ command : str = str (argv [2 ]) if len (argv ) > 2 else None
174
+ args : str = ' ' .join (map (str , argv [3 :])) if len (argv ) > 3 else None
175
175
176
176
if hasattr (controller , command ):
177
177
command = getattr (controller , command )
0 commit comments