@@ -192,14 +192,12 @@ def convert_xml_dict_values(value):
192192
193193
194194def save_to_json_file (info_dict , filename , indent = 4 ):
195-
196195 strj = json .dumps (info_dict , indent = indent )
197196 with open (filename , "w" ) as fp :
198197 fp .write (strj )
199198
200199
201200def save_to_yaml_file (info_dict , filename , indent = 4 ):
202-
203201 if sys .version_info [0 ] == 2 :
204202 stry = yaml .dump (info_dict , indent = indent , default_flow_style = False )
205203 else :
@@ -251,7 +249,6 @@ def build_xml_element(data, parent=None):
251249
252250 attrs = attr .fields (data .__class__ )
253251 for aattr in attrs :
254-
255252 print_ (" == Looking at: {} ({})" .format (aattr , type (aattr )), verbose )
256253 if isinstance (aattr .default , attr .Factory ):
257254 children = data .__getattribute__ (aattr .name )
@@ -272,15 +269,14 @@ def build_xml_element(data, parent=None):
272269 )
273270 if attribute_value is not None :
274271 if (
275- type (attribute_value ) is int
276- or type (attribute_value ) is float
277- or type (attribute_value ) is str
278- or type (attribute_value ) is bool
279- or type (attribute_value ) is list
272+ isinstance (attribute_value , int )
273+ or isinstance (attribute_value , float )
274+ or isinstance (attribute_value , str )
275+ or isinstance (attribute_value , bool )
276+ or isinstance (attribute_value , list )
280277 ):
281278 parent .set (attribute_name , str (attribute_value ))
282- elif type (attribute_value ) == dict :
283-
279+ elif isinstance (attribute_value , dict ):
284280 """for k, v in attribute_value.items():
285281 child_element = build_xml_element(v)"""
286282 else :
@@ -309,7 +305,6 @@ def ascii_encode_dict(data):
309305
310306
311307def _parse_element (dict_format , to_build ):
312-
313308 print_ ("Parse for element: [%s]" % dict_format , verbose )
314309 for k in dict_format .keys ():
315310 print_ (
@@ -323,7 +318,6 @@ def _parse_element(dict_format, to_build):
323318
324319
325320def _parse_attributes (dict_format , to_build ):
326-
327321 for key in dict_format :
328322 value = dict_format [key ]
329323 new_format = True
@@ -333,7 +327,7 @@ def _parse_attributes(dict_format, to_build):
333327 )
334328
335329 if new_format :
336- if type (to_build ) == dict :
330+ if isinstance (to_build , dict ) :
337331 to_build [key ] = value
338332
339333 elif key in to_build .allowed_children :
@@ -345,11 +339,11 @@ def _parse_attributes(dict_format, to_build):
345339 exec ("to_build.%s.append(ff)" % key )
346340 else :
347341 if (
348- type (value ) == str
349- or type (value ) == int
350- or type (value ) == float
351- or type (value ) == bool
352- or type (value ) == list
342+ isinstance (value , str )
343+ or isinstance (value , int )
344+ or isinstance (value , float )
345+ or isinstance (value , bool )
346+ or isinstance (value , list )
353347 or value is None
354348 ):
355349 to_build .__setattr__ (key , value )
@@ -370,11 +364,15 @@ def _parse_attributes(dict_format, to_build):
370364 exec ("to_build.%s = ff" % key )
371365
372366 else :
373- if type (to_build ) == dict :
367+ if isinstance (to_build , dict ) :
374368 to_build [key ] = value
375- elif type (value ) == str or type (value ) == int or type (value ) == float :
369+ elif (
370+ isinstance (value , str )
371+ or isinstance (value , int )
372+ or isinstance (value , float )
373+ ):
376374 to_build .__setattr__ (key , value )
377- elif type (value ) == list :
375+ elif isinstance (value , list ) :
378376 type_to_use = to_build .allowed_children [key ][1 ]
379377
380378 for vl in value :
@@ -403,7 +401,7 @@ def locate_file(f, base_dir):
403401
404402
405403def _val_info (param_val ):
406- if type (param_val ) == np .ndarray :
404+ if isinstance (param_val , np .ndarray ) :
407405 pp = "%s" % (np .array2string (param_val , threshold = 4 , edgeitems = 1 ))
408406 pp = pp .replace ("\n " , "" )
409407 pp += f" (NP { param_val .shape } { param_val .dtype } )"
@@ -489,7 +487,6 @@ def evaluate(
489487 else :
490488 expr = int (expr )
491489 except :
492-
493490 try :
494491 if array_format == FORMAT_TENSORFLOW :
495492 expr = tf .constant (float (expr ))
@@ -557,7 +554,6 @@ def evaluate(
557554 )
558555
559556 if (type (v ) is float or type (v ) is str ) and int (v ) == v :
560-
561557 print_ (" Returning int: %s" % int (v ), verbose )
562558
563559 if array_format == FORMAT_TENSORFLOW :
@@ -576,7 +572,6 @@ def evaluate(
576572
577573
578574def parse_list_like (list_str ):
579-
580575 if isinstance (list_str , int ):
581576 return [list_str ]
582577 elif isinstance (list_str , float ):
0 commit comments