From e6fc9379e335e5e4dc392bfcb94153aed78bd889 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Sun, 24 Nov 2024 20:20:01 +0100 Subject: [PATCH] STY: Apply ruff/pyupgrade rule UP031 UP031 Use format specifiers instead of percent format --- nibabel/cmdline/utils.py | 2 +- nibabel/volumeutils.py | 3 +-- pyproject.toml | 1 + 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/nibabel/cmdline/utils.py b/nibabel/cmdline/utils.py index d89cc5c96..bcbb32591 100644 --- a/nibabel/cmdline/utils.py +++ b/nibabel/cmdline/utils.py @@ -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) diff --git a/nibabel/volumeutils.py b/nibabel/volumeutils.py index 67a3f9a58..03aeb440a 100644 --- a/nibabel/volumeutils.py +++ b/nibabel/volumeutils.py @@ -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) diff --git a/pyproject.toml b/pyproject.toml index 720366f53..a8ae3129b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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"