Skip to content

Commit 6cc0f31

Browse files
committed
Improve type annotations for the style parameter
This will use `typing.Literal` on Python versions where it is available.
1 parent 9fd61a8 commit 6cc0f31

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

colorlog/formatter.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
EscapeCodes = typing.Mapping[str, str]
1919
LogColors = typing.Mapping[str, str]
2020
SecondaryLogColors = typing.Mapping[str, LogColors]
21+
if sys.version_info >= (3, 8):
22+
_FormatStyle = typing.Literal["%", "{", "$"]
23+
else:
24+
_FormatStyle = str
2125

2226
# The default colors to use for the debug levels
2327
default_log_colors = {
@@ -60,7 +64,7 @@ def __init__(
6064
self,
6165
fmt: typing.Optional[str] = None,
6266
datefmt: typing.Optional[str] = None,
63-
style: str = "%",
67+
style: _FormatStyle = "%",
6468
log_colors: typing.Optional[LogColors] = None,
6569
reset: bool = True,
6670
secondary_log_colors: typing.Optional[SecondaryLogColors] = None,
@@ -89,7 +93,7 @@ def __init__(
8993
- reset (bool):
9094
Implicitly append a color reset to all records unless False.
9195
- style ('%' or '{' or '$'):
92-
The format style to use. (*No meaning prior to Python 3.2.*)
96+
The format style to use.
9397
- secondary_log_colors (dict):
9498
Map secondary ``log_color`` attributes. (*New in version 2.6.*)
9599
- validate (bool)

colorlog/wrappers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343

4444

4545
def basicConfig(
46-
style: str = "%",
46+
style: colorlog.formatter._FormatStyle = "%",
4747
log_colors: typing.Optional[colorlog.formatter.LogColors] = None,
4848
reset: bool = True,
4949
secondary_log_colors: typing.Optional[colorlog.formatter.SecondaryLogColors] = None,

0 commit comments

Comments
 (0)