@@ -43,7 +43,7 @@ def import_eds(source, node_id):
4343 if eds .has_section ("Comments" ):
4444 linecount = int (eds .get ("Comments" , "Lines" ), 0 )
4545 od .comments = '\n ' .join ([
46- eds .get ("Comments" , "Line%i" % line )
46+ eds .get ("Comments" , f "Line{ line } " )
4747 for line in range (1 , linecount + 1 )
4848 ])
4949
@@ -52,7 +52,7 @@ def import_eds(source, node_id):
5252 else :
5353 for rate in [10 , 20 , 50 , 125 , 250 , 500 , 800 , 1000 ]:
5454 baudPossible = int (
55- eds .get ("DeviceInfo" , "BaudRate_%i" % rate , fallback = '0' ), 0 )
55+ eds .get ("DeviceInfo" , f "BaudRate_{ rate } " , fallback = '0' ), 0 )
5656 if baudPossible != 0 :
5757 od .device_information .allowed_baudrates .add (rate * 1000 )
5858
@@ -93,7 +93,7 @@ def import_eds(source, node_id):
9393 match = re .match (r"^[Dd]ummy[Uu]sage$" , section )
9494 if match is not None :
9595 for i in range (1 , 8 ):
96- key = "Dummy% 04d" % i
96+ key = f "Dummy{ i : 04d} "
9797 if eds .getint (section , key ) == 1 :
9898 var = objectdictionary .ODVariable (key , i , 0 )
9999 var .data_type = i
@@ -239,7 +239,7 @@ def _revert_variable(var_type, value):
239239 elif var_type in datatypes .FLOAT_TYPES :
240240 return value
241241 else :
242- return "0x% 02X" % value
242+ return f "0x{ value : 02X} "
243243
244244
245245def build_variable (eds , section , node_id , index , subindex = 0 ):
@@ -264,9 +264,9 @@ def build_variable(eds, section, node_id, index, subindex=0):
264264 # The eds.get function gives us 0x00A0 now convert to String without hex representation and upper case
265265 # The sub2 part is then the section where the type parameter stands
266266 try :
267- var .data_type = int (eds .get ("%Xsub1" % var .data_type , "DefaultValue" ), 0 )
267+ var .data_type = int (eds .get (f" { var .data_type :X } sub1" , "DefaultValue" ), 0 )
268268 except NoSectionError :
269- logger .warning ("%s has an unknown or unsupported data type (%X)" , name , var .data_type )
269+ logger .warning ("%s has an unknown or unsupported data type (0x %X)" , name , var .data_type )
270270 # Assume DOMAIN to force application to interpret the byte data
271271 var .data_type = datatypes .DOMAIN
272272
@@ -354,15 +354,15 @@ def export_common(var, eds, section):
354354 def export_variable (var , eds ):
355355 if isinstance (var .parent , ObjectDictionary ):
356356 # top level variable
357- section = "%04X" % var .index
357+ section = f" { var .index :04X } "
358358 else :
359359 # nested variable
360- section = "%04Xsub%X" % ( var .index , var .subindex )
360+ section = f" { var .index :04X } sub { var .subindex :X } "
361361
362362 export_common (var , eds , section )
363- eds .set (section , "ObjectType" , "0x%X" % VAR )
363+ eds .set (section , "ObjectType" , f "0x{ VAR :X } " )
364364 if var .data_type :
365- eds .set (section , "DataType" , "0x%04X" % var .data_type )
365+ eds .set (section , "DataType" , f "0x{ var .data_type :04X } " )
366366 if var .access_type :
367367 eds .set (section , "AccessType" , var .access_type )
368368
@@ -379,7 +379,7 @@ def export_variable(var, eds):
379379 eds .set (section , "ParameterValue" ,
380380 _revert_variable (var .data_type , var .value ))
381381
382- eds .set (section , "DataType" , "0x%04X" % var .data_type )
382+ eds .set (section , "DataType" , f "0x{ var .data_type :04X } " )
383383 eds .set (section , "PDOMapping" , hex (var .pdo_mappable ))
384384
385385 if getattr (var , 'min' , None ) is not None :
@@ -395,11 +395,11 @@ def export_variable(var, eds):
395395 eds .set (section , "Unit" , var .unit )
396396
397397 def export_record (var , eds ):
398- section = "%04X" % var .index
398+ section = f" { var .index :04X } "
399399 export_common (var , eds , section )
400- eds .set (section , "SubNumber" , "0x%X" % len (var .subindices ))
400+ eds .set (section , "SubNumber" , f "0x{ len (var .subindices ):X } " )
401401 ot = RECORD if isinstance (var , objectdictionary .ODRecord ) else ARR
402- eds .set (section , "ObjectType" , "0x%X" % ot )
402+ eds .set (section , "ObjectType" , f "0x{ ot :X } " )
403403 for i in var :
404404 export_variable (var [i ], eds )
405405
@@ -461,7 +461,7 @@ def export_record(var, eds):
461461 for rate in od .device_information .allowed_baudrates .union (
462462 {10e3 , 20e3 , 50e3 , 125e3 , 250e3 , 500e3 , 800e3 , 1000e3 }):
463463 eds .set (
464- "DeviceInfo" , "BaudRate_%i" % ( rate / 1000 ) ,
464+ "DeviceInfo" , f "BaudRate_{ rate // 1000 } " ,
465465 int (rate in od .device_information .allowed_baudrates ))
466466
467467 if device_commisioning and (od .bitrate or od .node_id ):
@@ -475,12 +475,12 @@ def export_record(var, eds):
475475 i = 0
476476 for line in od .comments .splitlines ():
477477 i += 1
478- eds .set ("Comments" , "Line%i" % i , line )
478+ eds .set ("Comments" , f "Line{ i } " , line )
479479 eds .set ("Comments" , "Lines" , i )
480480
481481 eds .add_section ("DummyUsage" )
482482 for i in range (1 , 8 ):
483- key = "Dummy% 04d" % i
483+ key = f "Dummy{ i : 04d} "
484484 eds .set ("DummyUsage" , key , 1 if (key in od ) else 0 )
485485
486486 def mandatory_indices (x ):
@@ -504,7 +504,7 @@ def add_list(section, list):
504504 eds .add_section (section )
505505 eds .set (section , "SupportedObjects" , len (list ))
506506 for i in range (0 , len (list )):
507- eds .set (section , (i + 1 ), "0x%04X" % list [i ])
507+ eds .set (section , (i + 1 ), f "0x{ list [i ]:04X } " )
508508 for index in list :
509509 export_object (od [index ], eds )
510510
0 commit comments