chore: Improve typing

This commit is contained in:
Matthias
2024-07-07 08:36:51 +02:00
parent 9f628309e9
commit ffb0cf1a2c
2 changed files with 11 additions and 7 deletions
+4 -4
View File
@@ -1,7 +1,7 @@
import csv import csv
import logging import logging
import sys import sys
from typing import Any, Dict, List from typing import Any, Dict, List, Union
import rapidjson import rapidjson
from rich.console import Console from rich.console import Console
@@ -80,10 +80,10 @@ def start_list_exchanges(args: Dict[str, Any]) -> None:
def _print_objs_tabular(objs: List, print_colorized: bool) -> None: def _print_objs_tabular(objs: List, print_colorized: bool) -> None:
names = [s["name"] for s in objs] names = [s["name"] for s in objs]
objs_to_print = [ objs_to_print: List[Dict[str, Union[Text, str]]] = [
{ {
"name": Text(s["name"] if s["name"] else "--"), "name": Text(s["name"] if s["name"] else "--"),
"location": Text(s["location_rel"]), "location": s["location_rel"],
"status": ( "status": (
Text("LOAD FAILED", style="bold red") Text("LOAD FAILED", style="bold red")
if s["class"] is None if s["class"] is None
@@ -103,7 +103,7 @@ def _print_objs_tabular(objs: List, print_colorized: bool) -> None:
"sell-Params": str(len(s["hyperoptable"].get("sell", []))), "sell-Params": str(len(s["hyperoptable"].get("sell", []))),
} }
) )
table = Table(title="Available:") table = Table()
for header in objs_to_print[0].keys(): for header in objs_to_print[0].keys():
table.add_column(header.capitalize(), justify="right") table.add_column(header.capitalize(), justify="right")
+7 -3
View File
@@ -1,13 +1,17 @@
import sys import sys
from typing import Any, Dict, List, Optional from typing import Any, Dict, Optional, Sequence, Union
from rich.console import Console from rich.console import Console
from rich.table import Table from rich.table import Table
from rich.text import Text
TextOrString = Union[str, Text]
def print_rich_table( def print_rich_table(
tabular_data: List[Dict[str, Any]], tabular_data: Sequence[Union[Dict[str, Any], Sequence[TextOrString]]],
headers: List[str], headers: Sequence[str],
summary: Optional[str] = None, summary: Optional[str] = None,
*, *,
table_kwargs: Optional[Dict[str, Any]] = None, table_kwargs: Optional[Dict[str, Any]] = None,