Merge pull request #1657 from skshetry/json-indent-type-compat

Make indent param in console.print_json compatible to json.dumps' indent
This commit is contained in:
Will McGugan 2021-11-09 16:32:15 +00:00 committed by GitHub
commit 4cf891315f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 7 deletions

View File

@ -1625,7 +1625,7 @@ class Console:
json: Optional[str] = None,
*,
data: Any = None,
indent: int = 2,
indent: Union[None, int, str] = 2,
highlight: bool = True,
skip_keys: bool = False,
ensure_ascii: bool = True,
@ -1639,7 +1639,7 @@ class Console:
Args:
json (Optional[str]): A string containing JSON.
data (Any): If json is not supplied, then encode this data.
indent (int, optional): Number of spaces to indent. Defaults to 2.
indent (Union[None, int, str], optional): Number of spaces to indent. Defaults to 2.
highlight (bool, optional): Enable highlighting of output: Defaults to True.
skip_keys (bool, optional): Skip keys not of a basic type. Defaults to False.
ensure_ascii (bool, optional): Escape all non-ascii characters. Defaults to False.

View File

@ -1,5 +1,5 @@
from json import loads, dumps
from typing import Any, Callable, Optional
from typing import Any, Callable, Optional, Union
from .text import Text
from .highlighter import JSONHighlighter, NullHighlighter
@ -10,7 +10,7 @@ class JSON:
Args:
json (str): JSON encoded data.
indent (int, optional): Number of characters to indent by. Defaults to 2.
indent (Union[None, int, str], optional): Number of characters to indent by. Defaults to 2.
highlight (bool, optional): Enable highlighting. Defaults to True.
skip_keys (bool, optional): Skip keys not of a basic type. Defaults to False.
ensure_ascii (bool, optional): Escape all non-ascii characters. Defaults to False.
@ -24,7 +24,7 @@ class JSON:
def __init__(
self,
json: str,
indent: int = 2,
indent: Union[None, int, str] = 2,
highlight: bool = True,
skip_keys: bool = False,
ensure_ascii: bool = True,
@ -53,7 +53,7 @@ class JSON:
def from_data(
cls,
data: Any,
indent: int = 2,
indent: Union[None, int, str] = 2,
highlight: bool = True,
skip_keys: bool = False,
ensure_ascii: bool = True,
@ -66,7 +66,7 @@ class JSON:
Args:
data (Any): An object that may be encoded in to JSON
indent (int, optional): Number of characters to indent by. Defaults to 2.
indent (Union[None, int, str], optional): Number of characters to indent by. Defaults to 2.
highlight (bool, optional): Enable highlighting. Defaults to True.
default (Callable, optional): Optional callable which will be called for objects that cannot be serialized. Defaults to None.
skip_keys (bool, optional): Skip keys not of a basic type. Defaults to False.