Path 1: 5 calls (0.56)

None (5)

{'foo': '💩'} (2) [False, True, None, 'foo'] (1) {'name': 'apple', 'count': 1} (1) ['xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...

4 (2) 2 (2) None (1)

True (5)

False (5)

False (5)

True (5)

True (5)

None (5)

False (5)

1def print_json(
2        self,
3        json: Optional[str] = None,
4        *,
5        data: Any = None,
6        indent: Union[None, int, str] = 2,
7        highlight: bool = True,
8        skip_keys: bool = False,
9        ensure_ascii: bool = False,
10        check_circular: bool = True,
11        allow_nan: bool = True,
12        default: Optional[Callable[[Any], Any]] = None,
13        sort_keys: bool = False,
14    ) -> None:
15        """Pretty prints JSON. Output will be valid JSON.
16
17        Args:
18            json (Optional[str]): A string containing JSON.
19            data (Any): If json is not supplied, then encode this data.
20            indent (Union[None, int, str], optional): Number of spaces to indent. Defaults to 2.
21            highlight (bool, optional): Enable highlighting of output: Defaults to True.
22            skip_keys (bool, optional): Skip keys not of a basic type. Defaults to False.
23            ensure_ascii (bool, optional): Escape all non-ascii characters. Defaults to False.
24            check_circular (bool, optional): Check for circular references. Defaults to True.
25            allow_nan (bool, optional): Allow NaN and Infinity values. Defaults to True.
26            default (Callable, optional): A callable that converts values that can not be encoded
27                in to something that can be JSON encoded. Defaults to None.
28            sort_keys (bool, optional): Sort dictionary keys. Defaults to False.
29        """
30        from rich.json import JSON
31
32        if json is None:
33            json_renderable = JSON.from_data(
34                data,
35                indent=indent,
36                highlight=highlight,
37                skip_keys=skip_keys,
38                ensure_ascii=ensure_ascii,
39                check_circular=check_circular,
40                allow_nan=allow_nan,
41                default=default,
42                sort_keys=sort_keys,
43            )
44        else:
45            if not isinstance(json, str):
46                raise TypeError(
47                    f"json must be str. Did you mean print_json(data={json!r}) ?"
48                )
49            json_renderable = JSON(
50                json,
51                indent=indent,
52                highlight=highlight,
53                skip_keys=skip_keys,
54                ensure_ascii=ensure_ascii,
55                check_circular=check_circular,
56                allow_nan=allow_nan,
57                default=default,
58                sort_keys=sort_keys,
59            )
60        self.print(json_renderable, soft_wrap=True)
            

Path 2: 3 calls (0.33)

'[false, true, null, "foo"]' (2) '["xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", 20000000000...

None (3)

4 (3)

True (3)

False (3)

False (3)

True (3)

True (3)

None (3)

False (3)

1def print_json(
2        self,
3        json: Optional[str] = None,
4        *,
5        data: Any = None,
6        indent: Union[None, int, str] = 2,
7        highlight: bool = True,
8        skip_keys: bool = False,
9        ensure_ascii: bool = False,
10        check_circular: bool = True,
11        allow_nan: bool = True,
12        default: Optional[Callable[[Any], Any]] = None,
13        sort_keys: bool = False,
14    ) -> None:
15        """Pretty prints JSON. Output will be valid JSON.
16
17        Args:
18            json (Optional[str]): A string containing JSON.
19            data (Any): If json is not supplied, then encode this data.
20            indent (Union[None, int, str], optional): Number of spaces to indent. Defaults to 2.
21            highlight (bool, optional): Enable highlighting of output: Defaults to True.
22            skip_keys (bool, optional): Skip keys not of a basic type. Defaults to False.
23            ensure_ascii (bool, optional): Escape all non-ascii characters. Defaults to False.
24            check_circular (bool, optional): Check for circular references. Defaults to True.
25            allow_nan (bool, optional): Allow NaN and Infinity values. Defaults to True.
26            default (Callable, optional): A callable that converts values that can not be encoded
27                in to something that can be JSON encoded. Defaults to None.
28            sort_keys (bool, optional): Sort dictionary keys. Defaults to False.
29        """
30        from rich.json import JSON
31
32        if json is None:
33            json_renderable = JSON.from_data(
34                data,
35                indent=indent,
36                highlight=highlight,
37                skip_keys=skip_keys,
38                ensure_ascii=ensure_ascii,
39                check_circular=check_circular,
40                allow_nan=allow_nan,
41                default=default,
42                sort_keys=sort_keys,
43            )
44        else:
45            if not isinstance(json, str):
46                raise TypeError(
47                    f"json must be str. Did you mean print_json(data={json!r}) ?"
48                )
49            json_renderable = JSON(
50                json,
51                indent=indent,
52                highlight=highlight,
53                skip_keys=skip_keys,
54                ensure_ascii=ensure_ascii,
55                check_circular=check_circular,
56                allow_nan=allow_nan,
57                default=default,
58                sort_keys=sort_keys,
59            )
60        self.print(json_renderable, soft_wrap=True)
            

Path 3: 1 calls (0.11)

['foo'] (1)

None (1)

4 (1)

True (1)

False (1)

False (1)

True (1)

True (1)

None (1)

False (1)

TypeError (1)

1def print_json(
2        self,
3        json: Optional[str] = None,
4        *,
5        data: Any = None,
6        indent: Union[None, int, str] = 2,
7        highlight: bool = True,
8        skip_keys: bool = False,
9        ensure_ascii: bool = False,
10        check_circular: bool = True,
11        allow_nan: bool = True,
12        default: Optional[Callable[[Any], Any]] = None,
13        sort_keys: bool = False,
14    ) -> None:
15        """Pretty prints JSON. Output will be valid JSON.
16
17        Args:
18            json (Optional[str]): A string containing JSON.
19            data (Any): If json is not supplied, then encode this data.
20            indent (Union[None, int, str], optional): Number of spaces to indent. Defaults to 2.
21            highlight (bool, optional): Enable highlighting of output: Defaults to True.
22            skip_keys (bool, optional): Skip keys not of a basic type. Defaults to False.
23            ensure_ascii (bool, optional): Escape all non-ascii characters. Defaults to False.
24            check_circular (bool, optional): Check for circular references. Defaults to True.
25            allow_nan (bool, optional): Allow NaN and Infinity values. Defaults to True.
26            default (Callable, optional): A callable that converts values that can not be encoded
27                in to something that can be JSON encoded. Defaults to None.
28            sort_keys (bool, optional): Sort dictionary keys. Defaults to False.
29        """
30        from rich.json import JSON
31
32        if json is None:
33            json_renderable = JSON.from_data(
34                data,
35                indent=indent,
36                highlight=highlight,
37                skip_keys=skip_keys,
38                ensure_ascii=ensure_ascii,
39                check_circular=check_circular,
40                allow_nan=allow_nan,
41                default=default,
42                sort_keys=sort_keys,
43            )
44        else:
45            if not isinstance(json, str):
46                raise TypeError(
47                    f"json must be str. Did you mean print_json(data={json!r}) ?"
48                )
49            json_renderable = JSON(
50                json,
51                indent=indent,
52                highlight=highlight,
53                skip_keys=skip_keys,
54                ensure_ascii=ensure_ascii,
55                check_circular=check_circular,
56                allow_nan=allow_nan,
57                default=default,
58                sort_keys=sort_keys,
59            )
60        self.print(json_renderable, soft_wrap=True)