Skip to content

Commit 298c82b

Browse files
committed
refactor convert
1 parent 0208c0b commit 298c82b

File tree

4 files changed

+451
-25
lines changed

4 files changed

+451
-25
lines changed

gendiff/formater/to_plain.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
_DICT_CONVERT = {
2-
'0': 0,
3-
'False': 'false',
4-
'True': 'true',
5-
'None': 'null'
6-
}
7-
8-
91
def convert(elem):
102
if not isinstance(elem['value'], list):
11-
return _DICT_CONVERT.get(f"{elem['value']}", f"'{elem['value']}'")
3+
value = elem['value']
4+
if type(value) in (int, float, str):
5+
return f"'{value}'"
6+
if type(value) == bool:
7+
return str(value).lower()
8+
if value is None:
9+
return "null"
1210
return '[complex value]'
1311

1412

gendiff/formater/to_stylish.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,17 @@
55
'nested': ' '
66
}
77

8-
_DICT_CONVERT = {
9-
'False': 'false',
10-
'True': 'true',
11-
'None': 'null'
12-
}
13-
148
_INDENT = 4
159
_REPLACER = ' '
1610

1711

1812
def convert(elem):
19-
return _DICT_CONVERT.get(str(elem), elem)
13+
if type(elem) in (int, float, str):
14+
return elem
15+
if type(elem) == bool:
16+
return str(elem).lower()
17+
if elem is None:
18+
return "null"
2019

2120

2221
def get_stylish(diffs, lvl=1):

0 commit comments

Comments
 (0)