Skip to content

Commit e3174ee

Browse files
Apply ruff/pyupgrade rule UP031
These are manual fixes
1 parent 94ed7a9 commit e3174ee

4 files changed

Lines changed: 26 additions & 28 deletions

File tree

‎testing/cffi1/test_new_ffi_1.py‎

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ def test_integer_ranges(self):
119119

120120
def test_fixedsize_int(self):
121121
for size in [1, 2, 4, 8]:
122-
self._test_int_type(ffi, 'int%d_t' % (8*size), size, False)
123-
self._test_int_type(ffi, 'uint%d_t' % (8*size), size, True)
122+
self._test_int_type(ffi, f'int{8*size}_t', size, False)
123+
self._test_int_type(ffi, f'uint{8*size}_t', size, True)
124124
self._test_int_type(ffi, 'intptr_t', SIZE_OF_PTR, False)
125125
self._test_int_type(ffi, 'uintptr_t', SIZE_OF_PTR, True)
126126
self._test_int_type(ffi, 'ptrdiff_t', SIZE_OF_PTR, False)
@@ -288,10 +288,10 @@ def test_repr(self):
288288
assert repr(ffi.typeof(p)) == typerepr % "int *"
289289
#
290290
p = ffi.new("int*")
291-
assert repr(p) == "<cdata 'int *' owning %d bytes>" % SIZE_OF_INT
291+
assert repr(p) == f"<cdata 'int *' owning {SIZE_OF_INT} bytes>"
292292
assert repr(ffi.typeof(p)) == typerepr % "int *"
293293
p = ffi.new("int**")
294-
assert repr(p) == "<cdata 'int * *' owning %d bytes>" % SIZE_OF_PTR
294+
assert repr(p) == f"<cdata 'int * *' owning {SIZE_OF_PTR} bytes>"
295295
assert repr(ffi.typeof(p)) == typerepr % "int * *"
296296
p = ffi.new("int [2]")
297297
assert repr(p) == "<cdata 'int[2]' owning %d bytes>" % (2*SIZE_OF_INT)
@@ -575,8 +575,7 @@ def test_union_simple(self):
575575
assert u.a == -2
576576
with pytest.raises((AttributeError, TypeError)):
577577
del u.a
578-
assert repr(u) == "<cdata 'union simple_u *' owning %d bytes>" % (
579-
SIZE_OF_INT,)
578+
assert repr(u) == f"<cdata 'union simple_u *' owning {SIZE_OF_INT} bytes>"
580579

581580
def test_union_opaque(self):
582581
pytest.raises(ffi.error, ffi.new, "union baz*")
@@ -732,8 +731,7 @@ def cb(n):
732731
"<cdata 'int(*)(int)' calling <function cb at 0x")
733732
assert ffi.typeof(p) is ffi.typeof("int(*)(int)")
734733
q = ffi.new("int(**)(int)", p)
735-
assert repr(q) == "<cdata 'int(* *)(int)' owning %d bytes>" % (
736-
SIZE_OF_PTR)
734+
assert repr(q) == f"<cdata 'int(* *)(int)' owning {SIZE_OF_PTR} bytes>"
737735
with pytest.raises(TypeError):
738736
q(43)
739737
res = q[0](43)
@@ -984,7 +982,7 @@ def test_array_of_struct(self):
984982

985983
def test_pointer_to_array(self):
986984
p = ffi.new("int(**)[5]")
987-
assert repr(p) == "<cdata 'int(* *)[5]' owning %d bytes>" % SIZE_OF_PTR
985+
assert repr(p) == f"<cdata 'int(* *)[5]' owning {SIZE_OF_PTR} bytes>"
988986

989987
def test_iterate_array(self):
990988
a = ffi.new("char[]", b"hello")

‎testing/cffi1/test_parse_c_type.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def parsex(input):
131131
def str_if_int(x):
132132
if isinstance(x, str):
133133
return x
134-
return '%d,%d' % (x & 255, x >> 8)
134+
return f'{x & 255},{x >> 8}'
135135
return ' '.join(map(str_if_int, result))
136136

137137
def parse_error(input, expected_msg, expected_location):
@@ -302,9 +302,9 @@ def test_error():
302302

303303
def test_number_too_large():
304304
num_max = sys.maxsize
305-
assert parse("char[%d]" % num_max) == [Prim(lib._CFFI_PRIM_CHAR),
306-
'->', Array(0), num_max]
307-
parse_error("char[%d]" % (num_max + 1), "number too large", 5)
305+
assert parse(f"char[{num_max}]") == [Prim(lib._CFFI_PRIM_CHAR),
306+
'->', Array(0), num_max]
307+
parse_error(f"char[{num_max + 1}]", "number too large", 5)
308308

309309
def test_complexity_limit():
310310
parse_error("int" + "[]" * 2500, "internal type complexity limit reached",

‎testing/cffi1/test_recompiler.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -231,12 +231,12 @@ def test_macro_check_value():
231231
if sys.maxsize <= 2**32 or sys.platform == 'win32':
232232
vals.remove('-2147483648')
233233
ffi = FFI()
234-
cdef_lines = ['#define FOO_%d_%d %s' % (i, j, vals[i])
234+
cdef_lines = [f'#define FOO_{i}_{i} {vals[i]}'
235235
for i in range(len(vals))
236236
for j in range(len(vals))]
237237
ffi.cdef('\n'.join(cdef_lines))
238238

239-
verify_lines = ['#define FOO_%d_%d %s' % (i, j, vals[j]) # [j], not [i]
239+
verify_lines = [f'#define FOO_{i}_{j} {vals[j]}' # [j], not [i]
240240
for i in range(len(vals))
241241
for j in range(len(vals))]
242242
lib = verify(ffi, 'test_macro_check_value_ok',
@@ -249,7 +249,7 @@ def test_macro_check_value():
249249
c_compiler_msg += f' (0x{c_got:x})'
250250
#
251251
for i in range(len(vals)):
252-
attrname = 'FOO_%d_%d' % (i, j)
252+
attrname = f'FOO_{i}_{j}'
253253
if i == j:
254254
x = getattr(lib, attrname)
255255
assert x == c_got
@@ -510,9 +510,9 @@ def test_verify_anonymous_enum_with_typedef():
510510
assert repr(ffi.cast("e1", 2)) == "<cdata 'e1' 2: AA>"
511511
#
512512
ffi = FFI()
513-
ffi.cdef("typedef enum { AA=%d } e1;" % sys.maxsize)
513+
ffi.cdef(f"typedef enum {{ AA={sys.maxsize} }} e1;")
514514
lib = verify(ffi, 'test_verify_anonymous_enum_with_typedef2',
515-
"typedef enum { AA=%d } e1;" % sys.maxsize)
515+
f"typedef enum {{ AA={sys.maxsize} }} e1;")
516516
assert lib.AA == int(ffi.cast("long", sys.maxsize))
517517
assert ffi.sizeof("e1") == ffi.sizeof("long")
518518

@@ -2579,7 +2579,7 @@ def test_convert_api_mode_builtin_function_to_cdata():
25792579

25802580
def test_large_enum():
25812581
ffi = FFI()
2582-
biglist = ['nn%d' % i for i in range(6000)]
2582+
biglist = [f'nn{i}' for i in range(6000)]
25832583
ffi.cdef(
25842584
"""enum foo_s {{ {} }};""".format(','.join(biglist)))
25852585
lib = verify(ffi, "test_large_enum", """

‎testing/cffi1/test_verify1.py‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class FFI(FFI):
2626
def verify(self, preamble='', *args, **kwds):
2727
# HACK to reuse the tests from ../cffi0/test_verify.py
2828
FFI._verify_counter += 1
29-
module_name = 'verify%d' % FFI._verify_counter
29+
module_name = f'verify{FFI._verify_counter}'
3030
try:
3131
del self._assigned_source
3232
except AttributeError:
@@ -692,11 +692,11 @@ def test_global_const_int_size():
692692
ffi = FFI()
693693
if value == int(ffi.cast("long long", value)):
694694
if value < 0:
695-
vstr = '(-%dLL-1)' % (~value,)
695+
vstr = f'(-{~value}LL-1)'
696696
else:
697-
vstr = '%dLL' % value
697+
vstr = f'{value}LL'
698698
elif value == int(ffi.cast("unsigned long long", value)):
699-
vstr = '%dULL' % value
699+
vstr = f'{value}ULL'
700700
else:
701701
raise AssertionError(value)
702702
ffi.cdef("static const unsigned short AA;")
@@ -1734,10 +1734,10 @@ def test_enum_size():
17341734
('-2147483647-1', 4, -1),
17351735
]
17361736
if FFI().sizeof("long") == 8:
1737-
cases += [('4294967296L', 8, 2**64-1),
1738-
('%dUL' % (2**64-1), 8, 2**64-1),
1739-
('-2147483649L', 8, -1),
1740-
('%dL-1L' % (1-2**63), 8, -1)]
1737+
cases += [('4294967296L', 8, 2**64-1),
1738+
(f'{2**64-1}UL', 8, 2**64-1),
1739+
('-2147483649L', 8, -1),
1740+
(f'{1-2**63}L-1L', 8, -1)]
17411741
for hidden_value, expected_size, expected_minus1 in cases:
17421742
if sys.platform == 'win32' and 'U' in hidden_value:
17431743
continue # skipped on Windows
@@ -1754,7 +1754,7 @@ def test_enum_size():
17541754
## for hidden_value, expected_size, expected_minus1 in cases:
17551755
## ffi = FFI()
17561756
## ffi.cdef("enum foo_e { AA, BB, ... };")
1757-
## lib = ffi.verify("enum foo_e { AA, BB=%s };" % hidden_value)
1757+
## lib = ffi.verify(f"enum foo_e {{ AA, BB={hidden_value} }};")
17581758
## assert lib.AA == 0
17591759
## assert ffi.sizeof("enum foo_e") == expected_size
17601760
## assert int(ffi.cast("enum foo_e", -1)) == expected_minus1

0 commit comments

Comments
 (0)