forked from realpython/materials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions.py
More file actions
34 lines (26 loc) · 825 Bytes
/
Copy pathoptions.py
File metadata and controls
34 lines (26 loc) · 825 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from typing import Required, TypedDict, Unpack
class Options(TypedDict, total=False):
line_width: int
level: Required[str]
propagate: bool
def show_options(program_name: str, **kwargs: Unpack[Options]) -> None:
print(program_name.upper())
for option, value in kwargs.items():
print(f"{option:<15} {value}")
def show_options_explicit(
program_name: str,
*,
level: str,
line_width: int | None = None,
propagate: bool | None = None,
) -> None:
options = {
"line_width": line_width,
"level": level,
"propagate": propagate,
}
print(program_name.upper())
for option, value in options.items():
if value is not None:
print(f"{option:<15} {value}")
show_options("logger", line_width=80, level="INFO", propagate=False)