diff --git a/stubs/tabulate/tabulate/__init__.pyi b/stubs/tabulate/tabulate/__init__.pyi index 9a312a37db14..9a41d0dd1c1d 100644 --- a/stubs/tabulate/tabulate/__init__.pyi +++ b/stubs/tabulate/tabulate/__init__.pyi @@ -1,5 +1,5 @@ -from collections.abc import Callable, Container, Iterable, Mapping, Sequence -from typing import Any, Final, Literal, NamedTuple, TypeAlias +from collections.abc import Callable, Container, Iterable, Iterator, Mapping, Sequence +from typing import Any, Final, Literal, NamedTuple, Protocol, TypeAlias, type_check_only from typing_extensions import Self __all__ = ["tabulate", "tabulate_formats", "simple_separated_format"] @@ -41,10 +41,25 @@ LATEX_ESCAPE_RULES: Final[dict[str, str]] tabulate_formats: list[str] multiline_formats: dict[str, str] +@type_check_only +class _IndexLike(Protocol): + def __iter__(self) -> Iterator[Any]: ... + @property + def name(self) -> Any: ... + +@type_check_only +class _DataFrameLike(Protocol): + def __iter__(self) -> Iterator[Any]: ... + def keys(self) -> Any: ... + @property + def values(self) -> Iterable[Any]: ... + @property + def index(self) -> _IndexLike: ... + def simple_separated_format(separator: str) -> TableFormat: ... def tabulate( # The key is converted using str(). - tabular_data: Mapping[Any, Iterable[Any]] | Iterable[Iterable[Any]], + tabular_data: Mapping[Any, Iterable[Any]] | Iterable[Iterable[Any]] | _DataFrameLike, headers: str | dict[str, str] | Sequence[str] = (), tablefmt: str | TableFormat = "simple", floatfmt: str | Iterable[str] = "g",