@@ -242,13 +242,15 @@ def _memory_to_resource(self):
242
242
243
243
def _validate_types (self ):
244
244
"""Validate the types of all fields in the ClusterConfiguration dataclass."""
245
+ errors = []
245
246
for field_info in fields (self ):
246
247
value = getattr (self , field_info .name )
247
248
expected_type = field_info .type
248
249
if not self ._is_type (value , expected_type ):
249
- raise TypeError (
250
- f"'{ field_info .name } ' should be of type { expected_type } "
251
- )
250
+ errors .append (f"'{ field_info .name } ' should be of type { expected_type } ." )
251
+
252
+ if errors :
253
+ raise TypeError ("Type validation failed:\n " + "\n " .join (errors ))
252
254
253
255
@staticmethod
254
256
def _is_type (value , expected_type ):
@@ -268,6 +270,11 @@ def check_type(value, expected_type):
268
270
)
269
271
if origin_type is tuple :
270
272
return all (check_type (elem , etype ) for elem , etype in zip (value , args ))
271
- return isinstance (value , expected_type )
273
+ if isinstance (expected_type , type ):
274
+ if expected_type is int :
275
+ return isinstance (value , int ) and not isinstance (value , bool )
276
+ if expected_type is bool :
277
+ return isinstance (value , bool )
278
+ return isinstance (value , expected_type )
272
279
273
280
return check_type (value , expected_type )
0 commit comments