@@ -144,7 +144,7 @@ def __update_meta_params(self):
144
144
self .var_row_sep = self .__get_row_sep_str ()
145
145
self .var_row_sep_last = self .__get_row_sep_last ()
146
146
147
- def __validate_parameters (self ):
147
+ def __validate_parameters (self ): # noqa: C901
148
148
valid_values = {
149
149
"row_sep" : ["always" , "topbottom" , "markdown" , None ],
150
150
"emoji_spacing" : ["mono" , None ],
@@ -155,41 +155,49 @@ def __validate_parameters(self):
155
155
"padding_weight" : ["left" , "right" , "centerleft" , "centerright" ],
156
156
}
157
157
158
+ # Validate fixed value attributes
158
159
for attr , values in valid_values .items ():
159
160
if getattr (self , attr ) not in values :
160
161
raise ValueError (f"{ attr } value of '{ getattr (self , attr )} ' is not valid. Possible values are { values } ." )
161
-
162
+
163
+ # Validate padding_weight
162
164
if isinstance (self .padding_weight , dict ):
163
- for attr , values in valid_dict_values .items ():
164
- for key , value in dict (getattr (self , attr )).items ():
165
- if value not in values :
166
- raise ValueError (f"padding_weight[{ key } ] value of '{ value } ' is not valid. Possible values are { values } ." )
165
+ for key , value in self .padding_weight .items ():
166
+ if value not in valid_dict_values ["padding_weight" ]:
167
+ raise ValueError (f"padding_weight[{ key } ] value of '{ value } ' is not valid. Possible values are { valid_dict_values ['padding_weight' ]} ." )
167
168
else :
168
169
raise ValueError (f"padding_weight value of '{ self .padding_weight } ' is not valid." )
169
170
171
+ # Validate padding_width
170
172
if isinstance (self .padding_width , dict ):
171
173
for key , value in self .padding_width .items ():
172
- if not isinstance (value , int ) and ( value < 0 and value > 100000 ):
173
- raise ValueError (f"padding_width[{ key } ] value of '{ value } ' is not valid. Possible ranges of values are 0 < and > 100000." )
174
+ if not isinstance (value , int ) or not ( 0 <= value < 100000 ):
175
+ raise ValueError (f"padding_width[{ key } ] value of '{ value } ' is not valid. Possible range is 0 <= value < 100000." )
174
176
else :
175
177
raise ValueError (f"padding_width value of '{ self .padding_width } ' is not valid." )
176
178
177
- if not isinstance (self .padding_char , (str , dict )) or len (self .padding_char ) != 1 :
179
+ # Validate padding_char
180
+ if not isinstance (self .padding_char , (str , dict )) or (isinstance (self .padding_char , str ) and len (self .padding_char ) != 1 ):
178
181
raise ValueError (f"padding_char value of '{ self .padding_char } ' is not valid. Please use a single character string." )
179
182
183
+ # Validate float_rounding
180
184
if not isinstance (self .float_rounding , (type (None ), int )):
181
185
raise ValueError (f"float_rounding value of '{ self .float_rounding } ' is not valid. Please use an integer or leave as None." )
182
186
187
+ # Validate multiline
183
188
if not isinstance (self .multiline , (type (None ), dict )):
184
189
raise ValueError (f"multiline value of '{ self .multiline } ' is not valid. Please use a dict or leave as None." )
185
190
191
+ # Validate multiline_delimiter
186
192
if not isinstance (self .multiline_delimiter , str ) or len (self .multiline_delimiter ) != 1 :
187
193
raise ValueError (f"multiline_delimiter value of '{ self .multiline_delimiter } ' is not valid. Please use a single character string." )
188
194
195
+ # Validate quote
189
196
if not isinstance (self .quote , bool ):
190
197
raise ValueError (f"quote value of '{ self .quote } ' is not valid. Please use a boolean." )
191
198
192
199
200
+
193
201
def __validate_data (self , data ):
194
202
# Check if all dictionaries in self.data have uniform keys
195
203
keys = set (data [0 ].keys ()) # Use set for fast lookup
0 commit comments