diff --git a/py-polars/polars/config.py b/py-polars/polars/config.py index 0ad1dfb985f9..777f400fd8f5 100644 --- a/py-polars/polars/config.py +++ b/py-polars/polars/config.py @@ -3,7 +3,7 @@ import contextlib import os from pathlib import Path -from typing import TYPE_CHECKING, Any, Literal, get_args +from typing import TYPE_CHECKING, Literal, TypedDict, get_args from polars._utils.various import normalize_filepath from polars.dependencies import json @@ -20,9 +20,9 @@ from typing_extensions import TypeAlias if sys.version_info >= (3, 11): - from typing import Self + from typing import Self, Unpack else: - from typing_extensions import Self + from typing_extensions import Self, Unpack __all__ = ["Config"] @@ -87,6 +87,35 @@ } +class ConfigParameters(TypedDict, total=False): + """Parameters supported by the polars Config.""" + + ascii_tables: bool | None + auto_structify: bool | None + decimal_separator: str | None + thousands_separator: str | bool | None + float_precision: int | None + fmt_float: FloatFmt | None + fmt_str_lengths: int | None + fmt_table_cell_list_len: int | None + streaming_chunk_size: int | None + tbl_cell_alignment: Literal["LEFT", "CENTER", "RIGHT"] | None + tbl_cell_numeric_alignment: Literal["LEFT", "CENTER", "RIGHT"] | None + tbl_cols: int | None + tbl_column_data_type_inline: bool | None + tbl_dataframe_shape_below: bool | None + tbl_formatting: TableFormatNames | None + tbl_hide_column_data_types: bool | None + tbl_hide_column_names: bool | None + tbl_hide_dtype_separator: bool | None + tbl_hide_dataframe_shape: bool | None + tbl_rows: int | None + tbl_width_chars: int | None + trim_decimal_zeros: bool | None + verbose: bool | None + expr_depth_warning: int + + class Config(contextlib.ContextDecorator): """ Configure polars; offers options for table formatting and more. @@ -118,7 +147,7 @@ class Config(contextlib.ContextDecorator): _original_state: str = "" - def __init__(self, *, restore_defaults: bool = False, **options: Any) -> None: + def __init__(self, *, restore_defaults: bool = False, **options: Unpack[ConfigParameters]) -> None: """ Initialise a Config object instance for context manager usage.