2from typing
import TYPE_CHECKING, Any, Optional, Tuple
15 scope:
"Mapping[str, Any]",
17 title: Optional[TextType] =
None,
18 sort_keys: bool =
True,
19 indent_guides: bool =
False,
20 max_length: Optional[int] =
None,
21 max_string: Optional[int] =
None,
22) ->
"ConsoleRenderable":
23 """Render python variables in a given scope.
26 scope (Mapping): A mapping containing variable names and values.
27 title (str, optional): Optional title. Defaults to None.
28 sort_keys (bool, optional): Enable sorting of items. Defaults to True.
29 indent_guides (bool, optional): Enable indentation guides. Defaults to False.
30 max_length (int, optional): Maximum length of containers before abbreviating, or None for no abbreviation.
32 max_string (int, optional): Maximum length of string before truncating, or None to disable. Defaults to None.
35 ConsoleRenderable: A renderable object.
38 items_table =
Table.grid(padding=(0, 1), expand=
False)
41 def sort_items(item: Tuple[str, Any]) -> Tuple[bool, str]:
42 """Sort special variables first, then alphabetically."""
47 for key, value
in items:
49 (key,
"scope.key.special" if key.startswith(
"__")
else "scope.key"),
50 (
" =",
"scope.equals"),
56 highlighter=highlighter,
57 indent_guides=indent_guides,
58 max_length=max_length,
59 max_string=max_string,
65 border_style=
"scope.border",
75 def test(foo: float, bar: float) ->
None:
76 list_of_things = [1, 2, 3,
None, 4,
True,
False,
"Hello World"]
79 "method":
"confirmFruitPurchase",
80 "params": [[
"apple",
"orange",
"mangoes",
"pomelo"], 1.123],
83 print(render_scope(locals(), title=
"[i]locals", sort_keys=
False))