Skip to content

Commit

Permalink
STY: Apply ruff/pyupgrade rule UP031
Browse files Browse the repository at this point in the history
UP031 Use format specifiers instead of percent format
  • Loading branch information
DimitriPapadopoulos committed Dec 11, 2024
1 parent 655df17 commit 386b6ee
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions nibabel/cmdline/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def table2string(table, out=None):
markup_strip = re.compile('^@([lrc]|w.*)')
col_width = [max(len(markup_strip.sub('', x)) for x in column) for column in atable.T]
string = ''
for i, table_ in enumerate(table):
for table_ in table:
string_ = ''
for j, item in enumerate(table_):
item = str(item)
Expand All @@ -89,7 +89,7 @@ def table2string(table, out=None):
else:
raise RuntimeError(f'Should not get here with align={align}')

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

Expand Down
3 changes: 1 addition & 2 deletions nibabel/volumeutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,11 +338,10 @@ def pretty_mapping(
if getterfunc is None:
getterfunc = getitem
mxlen = max(len(str(name)) for name in mapping)
fmt = '%%-%ds : %%s' % mxlen
out = []
for name in mapping:
value = getterfunc(mapping, name)
out.append(fmt % (name, value))
out.append(f'{name:{mxlen}} : {value}')
return '\n'.join(out)


Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ ignore = [
[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["F401"]
"doc/source/conf.py" = ["F401"]
"nibabel/benchmarks/*.py" = ["UP031"]

[tool.ruff.format]
quote-style = "single"
Expand Down

0 comments on commit 386b6ee

Please sign in to comment.