Skip to content

Commit

Permalink
Improve type annotations for the style parameter
Browse files Browse the repository at this point in the history
This will use `typing.Literal` on Python versions where it is available.
  • Loading branch information
borntyping committed Aug 29, 2022
1 parent 9fd61a8 commit 6cc0f31
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions colorlog/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
EscapeCodes = typing.Mapping[str, str]
LogColors = typing.Mapping[str, str]
SecondaryLogColors = typing.Mapping[str, LogColors]
if sys.version_info >= (3, 8):
_FormatStyle = typing.Literal["%", "{", "$"]
else:
_FormatStyle = str

# The default colors to use for the debug levels
default_log_colors = {
Expand Down Expand Up @@ -60,7 +64,7 @@ def __init__(
self,
fmt: typing.Optional[str] = None,
datefmt: typing.Optional[str] = None,
style: str = "%",
style: _FormatStyle = "%",
log_colors: typing.Optional[LogColors] = None,
reset: bool = True,
secondary_log_colors: typing.Optional[SecondaryLogColors] = None,
Expand Down Expand Up @@ -89,7 +93,7 @@ def __init__(
- reset (bool):
Implicitly append a color reset to all records unless False.
- style ('%' or '{' or '$'):
The format style to use. (*No meaning prior to Python 3.2.*)
The format style to use.
- secondary_log_colors (dict):
Map secondary ``log_color`` attributes. (*New in version 2.6.*)
- validate (bool)
Expand Down
2 changes: 1 addition & 1 deletion colorlog/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@


def basicConfig(
style: str = "%",
style: colorlog.formatter._FormatStyle = "%",
log_colors: typing.Optional[colorlog.formatter.LogColors] = None,
reset: bool = True,
secondary_log_colors: typing.Optional[colorlog.formatter.SecondaryLogColors] = None,
Expand Down

0 comments on commit 6cc0f31

Please sign in to comment.