Skip to content

Commit

Permalink
change default type of file parameter to None and use stdout if None
Browse files Browse the repository at this point in the history
  • Loading branch information
clarketm committed Nov 5, 2018
1 parent 16e3327 commit 8cc59a3
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions pprintjson/pprintjson.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
"""pprintjson module"""

from sys import stdout, argv
from json import dumps, loads
from sys import stdout, argv
from typing import Dict, IO, List, Union

from pygments import highlight
from pygments.lexers import JsonLexer
from pygments.formatters import TerminalFormatter
from typing import Dict, IO, List, Union
from pygments.lexers import JsonLexer


def pprintjson(
obj: Union[Dict, List],
indent: int = 4,
end: str = "\n",
file: IO = stdout,
file: IO = None,
flush: bool = False,
) -> None:
file = stdout if file is None else file
json = dumps(obj, indent=indent)
if file.isatty():
json = highlight(json, JsonLexer(), TerminalFormatter())
Expand Down

0 comments on commit 8cc59a3

Please sign in to comment.