diff --git a/poetry.lock b/poetry.lock index f2296e5..45438a1 100644 --- a/poetry.lock +++ b/poetry.lock @@ -383,13 +383,13 @@ files = [ [[package]] name = "multimethod" -version = "1.10" +version = "1.11.2" description = "Multiple argument dispatching." optional = false -python-versions = ">=3.8" +python-versions = ">=3.9" files = [ - {file = "multimethod-1.10-py3-none-any.whl", hash = "sha256:afd84da9c3d0445c84f827e4d63ad42d17c6d29b122427c6dee9032ac2d2a0d4"}, - {file = "multimethod-1.10.tar.gz", hash = "sha256:daa45af3fe257f73abb69673fd54ddeaf31df0eb7363ad6e1251b7c9b192d8c5"}, + {file = "multimethod-1.11.2-py3-none-any.whl", hash = "sha256:cb338f09395c0ee87d36c7691cdd794d13d8864358082cf1205f812edd5ce05a"}, + {file = "multimethod-1.11.2.tar.gz", hash = "sha256:7f2a4863967142e6db68632fef9cd79053c09670ba0c5f113301e245140bba5c"}, ] [[package]] @@ -702,7 +702,6 @@ files = [ [package.dependencies] markdown-it-py = ">=2.2.0" pygments = ">=2.13.0,<3.0.0" -typing-extensions = {version = ">=4.0.0,<5.0", markers = "python_version < \"3.9\""} [package.extras] jupyter = ["ipywidgets (>=7.5.1,<9)"] @@ -825,5 +824,5 @@ hue = ["rgbxy"] [metadata] lock-version = "2.0" -python-versions = ">=3.8,<4" -content-hash = "366f2526e99c7bc4443e6fc406818fffca06db46750653e9b54a000c1669291a" +python-versions = ">=3.9,<4" +content-hash = "26594f8cc1dc73082aea2bf77d21f512a19cd2c3c8014e9449be8acd11543ee3" diff --git a/pyproject.toml b/pyproject.toml index d93855d..93d8cce 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,7 +19,7 @@ classifiers = [ ] [tool.poetry.dependencies] -python = ">=3.8,<4" +python = ">=3.9,<4" rich = ">=12.3.0" multimethod = "*" diff --git a/rich_tables/generic.py b/rich_tables/generic.py index ef9754d..1fe8d22 100644 --- a/rich_tables/generic.py +++ b/rich_tables/generic.py @@ -3,7 +3,7 @@ import os from datetime import datetime from functools import partial, wraps -from typing import Any, Callable, Dict, List, TypeVar, Union +from typing import Any, Callable, Dict, List, Tuple, TypeVar, Union from multimethod import multidispatch from rich import box @@ -61,10 +61,16 @@ def time_fmt(current: datetime) -> Text: log.setLevel("DEBUG") -def _debug(_func: Callable[..., T]) -> None: +def _debug(_func: Callable[..., T], *args) -> None: if log.isEnabledFor(10): global indent types = f"\033[1;33m{list(_func.__annotations__.values())[:-1]}\033[0m" + + data, *header = [str(arg).split(r"\n")[0] for arg in args] + if header: + print(indent + f"Header: \033[1m{header[0] if header else ''}\033[0m") + elif data: + print(indent + f"Data: \033[1m{data}\033[0m") print(indent + f"Function \033[1;31m{_func.__name__}\033[0m, types: {types}") indent += "│ " @@ -74,11 +80,11 @@ def _undebug(_type: type, *args: Any) -> None: global indent indent = indent[:-2] if log.isEnabledFor(10): - data, *header = [str(arg).split(r"\n")[0] for arg in args] - if header: - print(indent + f"Header: \033[1m{header[0] if header else ''}\033[0m") - elif data: - print(indent + f"Data: \033[1m{data}\033[0m") + # data, *header = [str(arg).split(r"\n")[0] for arg in args] + # if header: + # print(indent + f"Header: \033[1m{header[0] if header else ''}\033[0m") + # elif data: + # print(indent + f"Data: \033[1m{data}\033[0m") print(indent + "└─ " + f"Returning {_type}") @@ -103,7 +109,7 @@ def prepare_dict(item: JSONDict) -> JSONDict: def debug(func: Callable[..., T]) -> Callable[..., T]: @wraps(func) def wrapper(*args: Any) -> T: - _debug(func) + _debug(func, *args) result = func(*args) _undebug(type(result), *args) return result @@ -192,19 +198,25 @@ def _json_dict(data: JSONDict) -> RenderableType: @flexitable.register @debug -def _str_list(data: List[str]) -> RenderableType: +def _list(data: List) -> RenderableType: + return flexitable(tuple(data)) + + +@flexitable.register +@debug +def _str_list(data: Tuple[str, ...]) -> RenderableType: return format_with_color(data) @flexitable.register @debug -def _int_list(data: List[int]) -> Panel: +def _int_list(data: Tuple[int, ...]) -> Panel: return border_panel(Columns(str(x) for x in data)) @flexitable.register @debug -def _dict_list(data: List[JSONDict]) -> RenderableType: +def _dict_list(data: Tuple[JSONDict, ...]) -> RenderableType: if len(data) == 1 and len(data[0]) > 10: return flexitable(data[0])