@@ -262,8 +262,13 @@ def __init__(self, params_type, **kwargs):
262262 self .__dict__ .update (__params_type__ = params_type , __signatures__ = None )
263263
264264 def __repr__ (self ):
265- return "Params(%s)" % ", " .join (
266- [(f"{ k } :{ type (self [k ]).__name__ } :{ self [k ]} " ) for k in sorted (self .keys ())]
265+ return "Params({})" .format (
266+ ", " .join (
267+ [
268+ (f"{ k } :{ type (self [k ]).__name__ } :{ self [k ]} " )
269+ for k in sorted (self .keys ())
270+ ]
271+ )
267272 )
268273
269274 def __getattr__ (self , key ):
@@ -346,13 +351,11 @@ def __init__(self, **kwargs):
346351 for attribute_name in kwargs :
347352 if re .match ("^[A-Za-z_][A-Za-z0-9_]*$" , attribute_name ) is None :
348353 raise AttributeError (
349- 'ParamsType: attribute "%s" should be a valid identifier.'
350- % attribute_name
354+ f'ParamsType: attribute "{ attribute_name } " should be a valid identifier.'
351355 )
352356 if attribute_name in c_cpp_keywords :
353357 raise SyntaxError (
354- 'ParamsType: "%s" is a potential C/C++ keyword and should not be used as attribute name.'
355- % attribute_name
358+ f'ParamsType: "{ attribute_name } " is a potential C/C++ keyword and should not be used as attribute name.'
356359 )
357360 type_instance = kwargs [attribute_name ]
358361 type_name = type_instance .__class__ .__name__
@@ -424,8 +427,10 @@ def __getattr__(self, key):
424427 return super ().__getattr__ (self , key )
425428
426429 def __repr__ (self ):
427- return "ParamsType<%s>" % ", " .join (
428- [(f"{ self .fields [i ]} :{ self .types [i ]} " ) for i in range (self .length )]
430+ return "ParamsType<{}>" .format (
431+ ", " .join (
432+ [(f"{ self .fields [i ]} :{ self .types [i ]} " ) for i in range (self .length )]
433+ )
429434 )
430435
431436 def __eq__ (self , other ):
@@ -733,18 +738,18 @@ def c_support_code(self, **kwargs):
733738 struct_cleanup = "\n " .join (c_cleanup_list )
734739 struct_extract = "\n \n " .join (c_extract_list )
735740 struct_extract_method = """
736- void extract(PyObject* object, int field_pos) {
737- switch(field_pos) {
741+ void extract(PyObject* object, int field_pos) {{
742+ switch(field_pos) {{
738743 // Extraction cases.
739- %s
744+ {}
740745 // Default case.
741746 default:
742- PyErr_Format(PyExc_TypeError, "ParamsType: no extraction defined for a field %% d.", field_pos);
747+ PyErr_Format(PyExc_TypeError, "ParamsType: no extraction defined for a field %d.", field_pos);
743748 this->setErrorOccurred();
744749 break;
745- }
746- }
747- """ % (
750+ }}
751+ }}
752+ """ . format (
748753 "\n " .join (
749754 [
750755 ("case %d: extract_%s(object); break;" % (i , self .fields [i ]))
@@ -866,7 +871,7 @@ def c_extract(self, name, sub, check_input=True, **kwargs):
866871 struct_name = self .name ,
867872 length = self .length ,
868873 fail = sub ["fail" ],
869- fields_list = '"%s"' % '", "' .join (self .fields ),
874+ fields_list = '"{}"' . format ( '", "' .join (self .fields ) ),
870875 )
871876 )
872877
0 commit comments