@@ -24,27 +24,30 @@ def get_current_time_as_html_fragment(self):
24
24
"""
25
25
26
26
import datetime
27
+ from typing import Callable
27
28
28
29
29
30
class ConstructorInjection :
30
-
31
- def __init__ (self , time_provider ):
31
+ def __init__ (self , time_provider : Callable ) -> None :
32
32
self .time_provider = time_provider
33
33
34
- def get_current_time_as_html_fragment (self ):
34
+ def get_current_time_as_html_fragment (self ) -> str :
35
35
current_time = self .time_provider ()
36
- current_time_as_html_fragment = "<span class=\" tinyBoldText\" >{}</span>" .format (current_time )
36
+ current_time_as_html_fragment = '<span class="tinyBoldText">{}</span>' .format (
37
+ current_time
38
+ )
37
39
return current_time_as_html_fragment
38
40
39
41
40
42
class ParameterInjection :
41
-
42
- def __init__ (self ):
43
+ def __init__ (self ) -> None :
43
44
pass
44
45
45
- def get_current_time_as_html_fragment (self , time_provider ) :
46
+ def get_current_time_as_html_fragment (self , time_provider : Callable ) -> str :
46
47
current_time = time_provider ()
47
- current_time_as_html_fragment = "<span class=\" tinyBoldText\" >{}</span>" .format (current_time )
48
+ current_time_as_html_fragment = '<span class="tinyBoldText">{}</span>' .format (
49
+ current_time
50
+ )
48
51
return current_time_as_html_fragment
49
52
50
53
@@ -54,16 +57,18 @@ class SetterInjection:
54
57
def __init__ (self ):
55
58
pass
56
59
57
- def set_time_provider (self , time_provider ):
60
+ def set_time_provider (self , time_provider : Callable ):
58
61
self .time_provider = time_provider
59
62
60
63
def get_current_time_as_html_fragment (self ):
61
64
current_time = self .time_provider ()
62
- current_time_as_html_fragment = "<span class=\" tinyBoldText\" >{}</span>" .format (current_time )
65
+ current_time_as_html_fragment = '<span class="tinyBoldText">{}</span>' .format (
66
+ current_time
67
+ )
63
68
return current_time_as_html_fragment
64
69
65
70
66
- def production_code_time_provider ():
71
+ def production_code_time_provider () -> str :
67
72
"""
68
73
Production code version of the time provider (just a wrapper for formatting
69
74
datetime for this example).
@@ -73,7 +78,7 @@ def production_code_time_provider():
73
78
return current_time_formatted
74
79
75
80
76
- def midnight_time_provider ():
81
+ def midnight_time_provider () -> str :
77
82
"""Hard-coded stub"""
78
83
return "24:01"
79
84
@@ -107,4 +112,5 @@ def main():
107
112
108
113
if __name__ == "__main__" :
109
114
import doctest
115
+
110
116
doctest .testmod (optionflags = doctest .ELLIPSIS )
0 commit comments