Skip to content

Commit e9d7ceb

Browse files
fix: Moved some dictionaries to __init__ methods.
`colors` in `Argparse.ColorizingHelpFormatter` class. `_level_name` in `Formatters._Formatter` class and `level_colors` in `Formatters.ColorizingFormatter` class. `sign_colors` in `PPrint.PrettyPrinter` class. `colors` in `TreePrint.TreePrint.Node` class.
1 parent 137582f commit e9d7ceb

8 files changed

Lines changed: 139 additions & 126 deletions

File tree

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ Help this project by [Donation](DONATE.md)
66
Changes
77
-----------
88

9+
### 2.5.3
10+
11+
Moved some dictionaries to `__init__` methods.
12+
`colors` in `Argparse.ColorizingHelpFormatter` class.
13+
`_level_name` in `Formatters._Formatter` class and `level_colors` in `Formatters.ColorizingFormatter` class.
14+
`sign_colors` in `PPrint.PrettyPrinter` class.
15+
`colors` in `TreePrint.TreePrint.Node` class.
16+
917
### 2.5.2
1018

1119
Improved type-hintings.

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,13 @@ python setup.py install
5353
Changes
5454
-------
5555

56-
### 2.5.2
56+
### 2.5.3
5757

58-
Improved type-hintings.
58+
Moved some dictionaries to `__init__` methods.
59+
`colors` in `Argparse.ColorizingHelpFormatter` class.
60+
`_level_name` in `Formatters._Formatter` class and `level_colors` in `Formatters.ColorizingFormatter` class.
61+
`sign_colors` in `PPrint.PrettyPrinter` class.
62+
`colors` in `TreePrint.TreePrint.Node` class.
5963

6064
[Full CHANGELOG](https://github.com/MPCodeWriter21/log21/blob/master/CHANGELOG.md)
6165

log21/Argparse.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,22 @@
1717

1818

1919
class ColorizingHelpFormatter(_argparse.HelpFormatter):
20-
colors = {
21-
'usage': 'Cyan',
22-
'brackets': 'LightRed',
23-
'switches': 'LightCyan',
24-
'values': 'Green',
25-
'colons': 'LightRed',
26-
'commas': 'LightRed',
27-
'section headers': 'LightGreen',
28-
'help': 'LightWhite',
29-
'choices': 'LightGreen'
30-
}
31-
32-
def __init__(self, prog, indent_increment=2, max_help_position=24, width=None, colors: _Mapping[str, str] = None):
20+
def __init__(self, prog, indent_increment=2, max_help_position=24, width=None,
21+
colors: _Optional[_Mapping[str, str]] = None):
3322
super().__init__(prog, indent_increment, max_help_position, width)
23+
24+
self.colors = {
25+
'usage': 'Cyan',
26+
'brackets': 'LightRed',
27+
'switches': 'LightCyan',
28+
'values': 'Green',
29+
'colons': 'LightRed',
30+
'commas': 'LightRed',
31+
'section headers': 'LightGreen',
32+
'help': 'LightWhite',
33+
'choices': 'LightGreen'
34+
}
35+
3436
if colors:
3537
for key, value in colors.items():
3638
if key in self.colors:

log21/Formatters.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,6 @@
1111

1212

1313
class _Formatter(__Formatter):
14-
_level_names: _Dict[int, str] = {
15-
DEBUG: 'DEBUG',
16-
INFO: 'INFO',
17-
WARNING: 'WARNING',
18-
ERROR: 'ERROR',
19-
CRITICAL: 'CRITICAL',
20-
PRINT: 'PRINT',
21-
INPUT: 'INPUT'
22-
}
23-
2414
def __init__(self, fmt: _Optional[str] = None, datefmt: _Optional[str] = None, style: str = '%',
2515
level_names: _Optional[_Mapping[int, str]] = None):
2616
"""
@@ -49,6 +39,17 @@ def __init__(self, fmt: _Optional[str] = None, datefmt: _Optional[str] = None, s
4939
>>>
5040
"""
5141
super().__init__(fmt=fmt, datefmt=datefmt, style=style)
42+
43+
self._level_names: _Dict[int, str] = {
44+
DEBUG: 'DEBUG',
45+
INFO: 'INFO',
46+
WARNING: 'WARNING',
47+
ERROR: 'ERROR',
48+
CRITICAL: 'CRITICAL',
49+
PRINT: 'PRINT',
50+
INPUT: 'INPUT'
51+
}
52+
5253
if level_names:
5354
for level, name in level_names.items():
5455
self.level_names[level] = name
@@ -89,16 +90,6 @@ def format(self, record) -> str:
8990

9091

9192
class ColorizingFormatter(_Formatter):
92-
# Default color values
93-
level_colors: _Dict[int, _Tuple[str, ...]] = {
94-
DEBUG: ('lightblue',),
95-
INFO: ('green',),
96-
WARNING: ('lightyellow',),
97-
ERROR: ('light red',),
98-
CRITICAL: ('background red', 'white'),
99-
PRINT: ('Cyan',),
100-
INPUT: ('Magenta',)
101-
}
10293
time_color: _Tuple[str, ...] = ('lightblue',)
10394
name_color = pathname_color = filename_color = module_color = func_name_color = thread_name_color = \
10495
message_color = tuple()
@@ -112,6 +103,15 @@ def __init__(self, fmt: _Optional[str] = None, datefmt: _Optional[str] = None, s
112103
thread_name_color: _Optional[_Tuple[str, ...]] = None,
113104
message_color: _Optional[_Tuple[str, ...]] = None):
114105
super().__init__(fmt=fmt, datefmt=datefmt, style=style, level_names=level_names)
106+
self.level_colors: _Dict[int, _Tuple[str, ...]] = {
107+
DEBUG: ('lightblue',),
108+
INFO: ('green',),
109+
WARNING: ('lightyellow',),
110+
ERROR: ('light red',),
111+
CRITICAL: ('background red', 'white'),
112+
PRINT: ('Cyan',),
113+
INPUT: ('Magenta',)
114+
}
115115
# Checks and sets colors
116116
if level_colors:
117117
if not isinstance(level_colors, _Mapping):

0 commit comments

Comments
 (0)