1
1
"""HTML formatting utilities for DataFusion DataFrames."""
2
2
3
- from typing import Any , Callable , Dict , List , Optional , Protocol , Type
4
-
5
-
3
+ from typing import (
4
+ Any ,
5
+ Callable ,
6
+ Dict ,
7
+ List ,
8
+ Optional ,
9
+ Protocol ,
10
+ Type ,
11
+ runtime_checkable ,
12
+ )
13
+
14
+
15
+ @runtime_checkable
6
16
class CellFormatter (Protocol ):
7
17
"""Protocol for cell value formatters."""
8
18
@@ -11,6 +21,7 @@ def __call__(self, value: Any) -> str:
11
21
...
12
22
13
23
24
+ @runtime_checkable
14
25
class StyleProvider (Protocol ):
15
26
"""Protocol for HTML style providers."""
16
27
@@ -78,6 +89,28 @@ def __init__(
78
89
show_truncation_message : bool = True ,
79
90
style_provider : Optional [StyleProvider ] = None ,
80
91
):
92
+ # Validate numeric parameters
93
+ if not isinstance (max_cell_length , int ) or max_cell_length <= 0 :
94
+ raise ValueError ("max_cell_length must be a positive integer" )
95
+ if not isinstance (max_width , int ) or max_width <= 0 :
96
+ raise ValueError ("max_width must be a positive integer" )
97
+ if not isinstance (max_height , int ) or max_height <= 0 :
98
+ raise ValueError ("max_height must be a positive integer" )
99
+
100
+ # Validate boolean parameters
101
+ if not isinstance (enable_cell_expansion , bool ):
102
+ raise TypeError ("enable_cell_expansion must be a boolean" )
103
+ if not isinstance (show_truncation_message , bool ):
104
+ raise TypeError ("show_truncation_message must be a boolean" )
105
+
106
+ # Validate custom_css
107
+ if custom_css is not None and not isinstance (custom_css , str ):
108
+ raise TypeError ("custom_css must be None or a string" )
109
+
110
+ # Validate style_provider
111
+ if style_provider is not None and not isinstance (style_provider , StyleProvider ):
112
+ raise TypeError ("style_provider must implement the StyleProvider protocol" )
113
+
81
114
self .max_cell_length = max_cell_length
82
115
self .max_width = max_width
83
116
self .max_height = max_height
0 commit comments