@@ -223,6 +223,18 @@ def check_type_of_param_value(key, val, auto_convert=False):
223223 return type_ok , newval
224224
225225
226+ def type_spec_to_string (type_spec ):
227+ """
228+ Convert the given type to the name of a constant defined in this file if any.
229+ If no (unique) constant is found the string representation of the type is returned.
230+ """
231+ candidates = [name for name , value in globals ().items () if name .isupper () and type_spec is value ]
232+ if len (candidates ) == 1 :
233+ return f"<type '{ candidates [0 ]} '>"
234+ else :
235+ return str (type_spec )
236+
237+
226238def convert_value_type (val , typ ):
227239 """
228240 Try to convert type of provided value to specific type.
@@ -232,23 +244,26 @@ def convert_value_type(val, typ):
232244 """
233245 # Shouldn't be called if the type is already correct
234246 if is_value_of_type (val , typ ):
235- _log .warning ("Value %s is already of specified target type %s, no conversion needed" , val , typ )
247+ _log .warning ("Value %s is already of specified target type %s, no conversion needed" ,
248+ val , type_spec_to_string (typ ))
236249 return val
237250
238251 try :
239252 func = TYPE_CONVERSION_FUNCTIONS [typ ]
240253 except KeyError :
241- raise EasyBuildError ("No conversion function available (yet) for target type %s" , typ )
254+ raise EasyBuildError ("No conversion function available (yet) for target type %s" , type_spec_to_string ( typ ) )
242255
243256 _log .debug ("Trying to convert value %s (type: %s) to %s using %s" , val , type (val ), typ , func )
244257 try :
245258 res = func (val )
246259 _log .debug ("Type conversion seems to have worked, new type: %s" , type (res ))
247260 except Exception as err :
248- raise EasyBuildError ("Converting type of %s (%s) to %s using %s failed: %s" , val , type (val ), typ , func , err )
261+ raise EasyBuildError ("Converting type of %s (%s) to %s using %s failed: %s" ,
262+ val , type (val ), type_spec_to_string (typ ), func , err )
249263
250264 if not is_value_of_type (res , typ ):
251- raise EasyBuildError ("Converting value %s to type %s didn't work as expected: got %s" , val , typ , type (res ))
265+ raise EasyBuildError ("Converting value %s to type %s didn't work as expected: got %s of type %s" ,
266+ val , type_spec_to_string (typ ), res , type (res ))
252267
253268 return res
254269
@@ -536,7 +551,7 @@ def _to_checksum(checksum, list_level=0, allow_dict=True):
536551 # When we already are in a tuple no further recursion is allowed -> set list_level very high
537552 return tuple (_to_checksum (x , list_level = 99 , allow_dict = allow_dict ) for x in checksum )
538553 else :
539- return list ( _to_checksum (x , list_level = list_level + 1 , allow_dict = allow_dict ) for x in checksum )
554+ return [ _to_checksum (x , list_level = list_level + 1 , allow_dict = allow_dict ) for x in checksum ]
540555 elif isinstance (checksum , dict ) and allow_dict :
541556 return {key : _to_checksum (value , allow_dict = False ) for key , value in checksum .items ()}
542557
0 commit comments