Skip to content

Commit b7589be

Browse files
committed
Prefer global functions
1 parent 177107b commit b7589be

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

Lib/json/tool.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,24 @@
2222
''', re.VERBOSE)
2323

2424

25-
def _colorize_json(json_str):
26-
colors = {
27-
'string': ANSIColors.GREEN,
28-
'number': ANSIColors.YELLOW,
29-
'boolean': ANSIColors.CYAN,
30-
'null': ANSIColors.CYAN,
31-
}
25+
_colors = {
26+
'string': ANSIColors.GREEN,
27+
'number': ANSIColors.YELLOW,
28+
'boolean': ANSIColors.CYAN,
29+
'null': ANSIColors.CYAN,
30+
}
31+
3232

33-
def replace(match):
34-
for key in colors:
35-
if m := match.group(key):
36-
color = colors[key]
37-
return f"{color}{m}{ANSIColors.RESET}"
38-
return match.group()
33+
def _replace_match_callback(match):
34+
for key in _colors:
35+
if m := match.group(key):
36+
color = _colors[key]
37+
return f"{color}{m}{ANSIColors.RESET}"
38+
return match.group()
3939

40-
return re.sub(_color_pattern, replace, json_str)
40+
41+
def _colorize_json(json_str):
42+
return re.sub(_color_pattern, _replace_match_callback, json_str)
4143

4244

4345
def main():

0 commit comments

Comments
 (0)