25
25
import logging
26
26
import os
27
27
import sys
28
+ from typing import Any , Dict
28
29
29
30
# Third-Party Libraries
30
31
import docopt
33
34
34
35
from ._version import __version__
35
36
36
- DEFAULT_ECHO_MESSAGE = "Hello World from the example default!"
37
+ DEFAULT_ECHO_MESSAGE : str = "Hello World from the example default!"
37
38
38
39
39
- def example_div (dividend , divisor ) :
40
+ def example_div (dividend : float , divisor : float ) -> float :
40
41
"""Print some logging messages."""
41
42
logging .debug ("This is a debug message" )
42
43
logging .info ("This is an info message" )
@@ -46,11 +47,11 @@ def example_div(dividend, divisor):
46
47
return dividend / divisor
47
48
48
49
49
- def main ():
50
+ def main () -> int :
50
51
"""Set up logging and call the example function."""
51
- args = docopt .docopt (__doc__ , version = __version__ )
52
+ args : Dict [ str , str ] = docopt .docopt (__doc__ , version = __version__ )
52
53
# Validate and convert arguments as needed
53
- schema = Schema (
54
+ schema : Schema = Schema (
54
55
{
55
56
"--log-level" : And (
56
57
str ,
@@ -70,16 +71,16 @@ def main():
70
71
)
71
72
72
73
try :
73
- args = schema .validate (args )
74
+ validated_args : Dict [ str , Any ] = schema .validate (args )
74
75
except SchemaError as err :
75
76
# Exit because one or more of the arguments were invalid
76
77
print (err , file = sys .stderr )
77
78
return 1
78
79
79
80
# Assign validated arguments to variables
80
- dividend = args ["<dividend>" ]
81
- divisor = args ["<divisor>" ]
82
- log_level = args ["--log-level" ]
81
+ dividend : int = validated_args ["<dividend>" ]
82
+ divisor : int = validated_args ["<divisor>" ]
83
+ log_level : str = validated_args ["--log-level" ]
83
84
84
85
# Set up logging
85
86
logging .basicConfig (
@@ -89,11 +90,11 @@ def main():
89
90
logging .info (f"{ dividend } / { divisor } == { example_div (dividend , divisor )} " )
90
91
91
92
# Access some data from an environment variable
92
- message = os .getenv ("ECHO_MESSAGE" , DEFAULT_ECHO_MESSAGE )
93
+ message : str = os .getenv ("ECHO_MESSAGE" , DEFAULT_ECHO_MESSAGE )
93
94
logging .info (f'ECHO_MESSAGE="{ message } "' )
94
95
95
96
# Access some data from our package data (see the setup.py)
96
- secret_message = (
97
+ secret_message : str = (
97
98
pkg_resources .resource_string ("example" , "data/secret.txt" )
98
99
.decode ("utf-8" )
99
100
.strip ()
0 commit comments