Skip to content

Commit

Permalink
refactor convert
Browse files Browse the repository at this point in the history
  • Loading branch information
prStudentka committed Mar 10, 2024
1 parent 0208c0b commit 298c82b
Show file tree
Hide file tree
Showing 4 changed files with 451 additions and 25 deletions.
16 changes: 7 additions & 9 deletions gendiff/formater/to_plain.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
_DICT_CONVERT = {
'0': 0,
'False': 'false',
'True': 'true',
'None': 'null'
}


def convert(elem):
if not isinstance(elem['value'], list):
return _DICT_CONVERT.get(f"{elem['value']}", f"'{elem['value']}'")
value = elem['value']
if type(value) in (int, float, str):
return f"'{value}'"
if type(value) == bool:
return str(value).lower()
if value is None:
return "null"
return '[complex value]'


Expand Down
13 changes: 6 additions & 7 deletions gendiff/formater/to_stylish.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@
'nested': ' '
}

_DICT_CONVERT = {
'False': 'false',
'True': 'true',
'None': 'null'
}

_INDENT = 4
_REPLACER = ' '


def convert(elem):
return _DICT_CONVERT.get(str(elem), elem)
if type(elem) in (int, float, str):
return elem
if type(elem) == bool:
return str(elem).lower()
if elem is None:
return "null"


def get_stylish(diffs, lvl=1):
Expand Down
Loading

0 comments on commit 298c82b

Please sign in to comment.