Since their inclusion in Python 3.6, f-strings have become the preferred
way to format strings with variable values as they are generally more
readable as the value substitution is in place and doesn't have to be
parsed from the list or arguments to `.format()`.
Where it does not impact readability (when the line is <120 characters),
swap usage of `.format()` to an f-string.
For lines that are not converted, inform the linter to ignore attempts
to upgrade those instances to f-strings [0]
[0]: https://docs.astral.sh/ruff/rules/f-string/
Signed-off-by: Vincent Fazio <vfazio@xes-inc.com>
Link: https://lore.kernel.org/r/20241114145116.2123714-23-vfazio@xes-inc.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
if current_version < required_kernel_version:
raise NotImplementedError(
- "linux kernel version must be at least {} - got {}".format(
- required_kernel_version, current_version
- )
+ f"linux kernel version must be at least {required_kernel_version} - got {current_version}"
)
pass
def test_open_chip_by_link(self) -> None:
- link = "/tmp/gpiod-py-test-link.{}".format(os.getpid())
+ link = f"/tmp/gpiod-py-test-link.{os.getpid()}"
sim = gpiosim.Chip()
with LinkGuard(sim.dev_path, link):
class ChipDevPathFromLink(TestCase):
def test_dev_path_open_by_link(self) -> None:
sim = gpiosim.Chip()
- link = "/tmp/gpiod-py-test-link.{}".format(os.getpid())
+ link = f"/tmp/gpiod-py-test-link.{os.getpid()}"
with LinkGuard(sim.dev_path, link):
with gpiod.Chip(link) as chip:
self.sim = None # type: ignore[assignment]
def test_repr(self) -> None:
- self.assertEqual(repr(self.chip), 'gpiod.Chip("{}")'.format(self.sim.dev_path))
+ self.assertEqual(repr(self.chip), f'gpiod.Chip("{self.sim.dev_path}")')
cmp = eval(repr(self.chip))
self.assertEqual(self.chip.path, cmp.path)
info = self.chip.get_info()
self.assertEqual(
str(self.chip),
- '<Chip path="{}" fd={} info=<ChipInfo name="{}" label="foobar" num_lines=4>>'.format(
+ '<Chip path="{}" fd={} info=<ChipInfo name="{}" label="foobar" num_lines=4>>'.format( # noqa: UP032
self.sim.dev_path, self.chip.fd, info.name
),
)
self.assertEqual(
str(info),
- '<ChipInfo name="{}" label="foobar" num_lines=16>'.format(sim.name),
+ f'<ChipInfo name="{sim.name}" label="foobar" num_lines=16>',
)
with chip.request_lines(config={(2, 6, 4, 1): None}) as req:
self.assertEqual(
str(req),
- '<LineRequest chip="{}" num_lines=4 offsets=[2, 6, 4, 1] fd={}>'.format(
- self.sim.name, req.fd
- ),
+ f'<LineRequest chip="{self.sim.name}" num_lines=4 offsets=[2, 6, 4, 1] fd={req.fd}>',
)
def test_str_released(self) -> None:
self.assertTrue(gpiod.is_gpiochip_device(path=sim.dev_path))
def test_is_gpiochip_link_good(self) -> None:
- link = "/tmp/gpiod-py-test-link.{}".format(os.getpid())
+ link = f"/tmp/gpiod-py-test-link.{os.getpid()}"
sim = gpiosim.Chip()
with LinkGuard(sim.dev_path, link):
self.assertTrue(gpiod.is_gpiochip_device(link))
def test_is_gpiochip_link_bad(self) -> None:
- link = "/tmp/gpiod-py-test-link.{}".format(os.getpid())
+ link = f"/tmp/gpiod-py-test-link.{os.getpid()}"
with LinkGuard("/dev/null", link):
self.assertFalse(gpiod.is_gpiochip_device(link))