@@ -262,8 +262,13 @@ def __init__(self, params_type, **kwargs):
262
262
self .__dict__ .update (__params_type__ = params_type , __signatures__ = None )
263
263
264
264
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
+ )
267
272
)
268
273
269
274
def __getattr__ (self , key ):
@@ -346,13 +351,11 @@ def __init__(self, **kwargs):
346
351
for attribute_name in kwargs :
347
352
if re .match ("^[A-Za-z_][A-Za-z0-9_]*$" , attribute_name ) is None :
348
353
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.'
351
355
)
352
356
if attribute_name in c_cpp_keywords :
353
357
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.'
356
359
)
357
360
type_instance = kwargs [attribute_name ]
358
361
type_name = type_instance .__class__ .__name__
@@ -424,8 +427,10 @@ def __getattr__(self, key):
424
427
return super ().__getattr__ (self , key )
425
428
426
429
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
+ )
429
434
)
430
435
431
436
def __eq__ (self , other ):
@@ -733,18 +738,18 @@ def c_support_code(self, **kwargs):
733
738
struct_cleanup = "\n " .join (c_cleanup_list )
734
739
struct_extract = "\n \n " .join (c_extract_list )
735
740
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) {{
738
743
// Extraction cases.
739
- %s
744
+ {}
740
745
// Default case.
741
746
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);
743
748
this->setErrorOccurred();
744
749
break;
745
- }
746
- }
747
- """ % (
750
+ }}
751
+ }}
752
+ """ . format (
748
753
"\n " .join (
749
754
[
750
755
("case %d: extract_%s(object); break;" % (i , self .fields [i ]))
@@ -866,7 +871,7 @@ def c_extract(self, name, sub, check_input=True, **kwargs):
866
871
struct_name = self .name ,
867
872
length = self .length ,
868
873
fail = sub ["fail" ],
869
- fields_list = '"%s"' % '", "' .join (self .fields ),
874
+ fields_list = '"{}"' . format ( '", "' .join (self .fields ) ),
870
875
)
871
876
)
872
877
0 commit comments