From 25905ab3dc783bf69871a7b443a7977b767d6f87 Mon Sep 17 00:00:00 2001 From: Richard Iannone Date: Tue, 12 Dec 2023 13:38:29 -0500 Subject: [PATCH] Fix CellStyleBorders based on code review comments --- great_tables/_styles.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/great_tables/_styles.py b/great_tables/_styles.py index 6bab1ecb8..60c95dbb5 100644 --- a/great_tables/_styles.py +++ b/great_tables/_styles.py @@ -186,14 +186,16 @@ class CellStyleBorders(CellStyle): A CellStyleBorders object, which is used for a `styles` argument if specifying cell borders. """ - sides: List[str] | str | None = "all" + sides: Literal["all", "top", "bottom", "left", "right"] | List[ + Literal["all", "top", "bottom", "left", "right"] + ] = "all" color: str = "#000000" style: str = "solid" weight: str = "1px" def _to_html_style(self) -> str: - # If sides is None, return an empty string - if self.sides is None: + # If sides is an empty list, return an empty string + if self.sides == []: return "" # If self.sides is a string, convert to a list @@ -213,6 +215,8 @@ def _to_html_style(self) -> str: border_css_list: List[str] = [] for side in self.sides: + if side not in ["top", "bottom", "left", "right"]: + raise ValueError(f"Invalid side '{side}' provided.") border_css_list.append(f"border-{side}: {weight} {style} {color};") border_css = "".join(border_css_list)