Skip to content

Commit 386b6ee

Browse files
STY: Apply ruff/pyupgrade rule UP031
UP031 Use format specifiers instead of percent format
1 parent 655df17 commit 386b6ee

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

nibabel/cmdline/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def table2string(table, out=None):
6565
markup_strip = re.compile('^@([lrc]|w.*)')
6666
col_width = [max(len(markup_strip.sub('', x)) for x in column) for column in atable.T]
6767
string = ''
68-
for i, table_ in enumerate(table):
68+
for table_ in table:
6969
string_ = ''
7070
for j, item in enumerate(table_):
7171
item = str(item)
@@ -89,7 +89,7 @@ def table2string(table, out=None):
8989
else:
9090
raise RuntimeError(f'Should not get here with align={align}')
9191

92-
string_ += '%%%ds%%s%%%ds ' % (nspacesl, nspacesr) % ('', item, '')
92+
string_ += f'{" " * nspacesl}{item}{" " * nspacesr} '
9393
string += string_.rstrip() + '\n'
9494
out.write(string)
9595

nibabel/volumeutils.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -338,11 +338,10 @@ def pretty_mapping(
338338
if getterfunc is None:
339339
getterfunc = getitem
340340
mxlen = max(len(str(name)) for name in mapping)
341-
fmt = '%%-%ds : %%s' % mxlen
342341
out = []
343342
for name in mapping:
344343
value = getterfunc(mapping, name)
345-
out.append(fmt % (name, value))
344+
out.append(f'{name:{mxlen}} : {value}')
346345
return '\n'.join(out)
347346

348347

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ ignore = [
182182
[tool.ruff.lint.per-file-ignores]
183183
"__init__.py" = ["F401"]
184184
"doc/source/conf.py" = ["F401"]
185+
"nibabel/benchmarks/*.py" = ["UP031"]
185186

186187
[tool.ruff.format]
187188
quote-style = "single"

0 commit comments

Comments
 (0)