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-15-vfazio@xes-inc.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
).items():
if count != 1:
raise ValueError(
- "line must be configured exactly once - offset {} repeats".format(
- offset
- )
+ f"line must be configured exactly once - offset {offset} repeats"
)
# If we have global output values - map line names to offsets
if not self._chip:
return "<Chip CLOSED>"
- return 'gpiod.Chip("{}")'.format(self.path)
+ return f'gpiod.Chip("{self.path}")'
def __str__(self) -> str:
"""
if not self._chip:
return "<Chip CLOSED>"
- return '<Chip path="{}" fd={} info={}>'.format(
- self.path, self.fd, self.get_info()
- )
+ return f'<Chip path="{self.path}" fd={self.fd} info={self.get_info()}>'
@property
def path(self) -> str:
num_lines: int
def __str__(self) -> str:
- return '<ChipInfo name="{}" label="{}" num_lines={}>'.format(
- self.name, self.label, self.num_lines
- )
+ return f'<ChipInfo name="{self.name}" label="{self.label}" num_lines={self.num_lines}>'
object.__setattr__(self, "line_seqno", line_seqno)
def __str__(self) -> str:
- return "<EdgeEvent type={} timestamp_ns={} line_offset={} global_seqno={} line_seqno={}>".format(
+ return "<EdgeEvent type={} timestamp_ns={} line_offset={} global_seqno={} line_seqno={}>".format( # noqa: UP032
self.event_type,
self.timestamp_ns,
self.line_offset,
object.__setattr__(self, "line_info", line_info)
def __str__(self) -> str:
- return "<InfoEvent type={} timestamp_ns={} line_info={}>".format(
- self.event_type, self.timestamp_ns, self.line_info
- )
+ return f"<InfoEvent type={self.event_type} timestamp_ns={self.timestamp_ns} line_info={self.line_info}>"
)
def __str__(self) -> str:
- return '<LineInfo offset={} name="{}" used={} consumer="{}" direction={} active_low={} bias={} drive={} edge_detection={} event_clock={} debounced={} debounce_period={}>'.format(
+ return '<LineInfo offset={} name="{}" used={} consumer="{}" direction={} active_low={} bias={} drive={} edge_detection={} event_clock={} debounced={} debounce_period={}>'.format( # noqa: UP032
self.offset,
self.name,
self.used,
if not self._req:
return "<LineRequest RELEASED>"
- return '<LineRequest chip="{}" num_lines={} offsets={} fd={}>'.format(
- self.chip_name, self.num_lines, self.offsets, self.fd
- )
+ return f'<LineRequest chip="{self.chip_name}" num_lines={self.num_lines} offsets={self.offsets} fd={self.fd}>'
@property
def chip_name(self) -> str:
# __repr__ generated by @dataclass uses repr for enum members resulting in
# an unusable representation as those are of the form: <NAME: $value>
def __repr__(self) -> str:
- return "gpiod.LineSettings(direction=gpiod.line.{}, edge_detection=gpiod.line.{}, bias=gpiod.line.{}, drive=gpiod.line.{}, active_low={}, debounce_period={}, event_clock=gpiod.line.{}, output_value=gpiod.line.{})".format(
+ return "gpiod.LineSettings(direction=gpiod.line.{}, edge_detection=gpiod.line.{}, bias=gpiod.line.{}, drive=gpiod.line.{}, active_low={}, debounce_period={}, event_clock=gpiod.line.{}, output_value=gpiod.line.{})".format( # noqa: UP032
str(self.direction),
str(self.edge_detection),
str(self.bias),
)
def __str__(self) -> str:
- return "<LineSettings direction={} edge_detection={} bias={} drive={} active_low={} debounce_period={} event_clock={} output_value={}>".format(
+ return "<LineSettings direction={} edge_detection={} bias={} drive={} active_low={} debounce_period={} event_clock={} output_value={}>".format( # noqa: UP032
self.direction,
self.edge_detection,
self.bias,