Skip to content

Commit

Permalink
bindings: python: selectively use f-strings
Browse files Browse the repository at this point in the history
Dataclasses are not migrated to f-strings as readability is reduced.

Signed-off-by: Vincent Fazio <vfazio@xes-inc.com>
  • Loading branch information
vfazio committed Sep 18, 2024
1 parent 7b90f27 commit 2f2381d
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 14 deletions.
8 changes: 3 additions & 5 deletions bindings/python/gpiod/chip.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,7 @@ def request_lines(
).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
Expand Down Expand Up @@ -351,7 +349,7 @@ def __repr__(self) -> str:
if not self._chip:
return "<Chip CLOSED>"

return 'gpiod.Chip("{}")'.format(self.path)
return f'gpiod.Chip("{self.path}")'

def __str__(self) -> str:
"""
Expand All @@ -360,7 +358,7 @@ def __str__(self) -> str:
if not self._chip:
return "<Chip CLOSED>"

return '<Chip path="{}" fd={} info={}>'.format(
return '<Chip path="{}" fd={} info={}>'.format( # noqa: UP032
self.path, self.fd, self.get_info()
)

Expand Down
2 changes: 1 addition & 1 deletion bindings/python/gpiod/chip_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ class ChipInfo:
num_lines: int

def __str__(self) -> str:
return '<ChipInfo name="{}" label="{}" num_lines={}>'.format(
return '<ChipInfo name="{}" label="{}" num_lines={}>'.format( # noqa: UP032
self.name, self.label, self.num_lines
)
2 changes: 1 addition & 1 deletion bindings/python/gpiod/edge_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def __init__(
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,
Expand Down
2 changes: 1 addition & 1 deletion bindings/python/gpiod/info_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ def __init__(self, event_type: int, timestamp_ns: int, line_info: LineInfo):
object.__setattr__(self, "line_info", line_info)

def __str__(self) -> str:
return "<InfoEvent type={} timestamp_ns={} line_info={}>".format(
return "<InfoEvent type={} timestamp_ns={} line_info={}>".format( # noqa: UP032
self.event_type, self.timestamp_ns, self.line_info
)
2 changes: 1 addition & 1 deletion bindings/python/gpiod/line_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def __init__(
)

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,
Expand Down
6 changes: 3 additions & 3 deletions bindings/python/gpiod/line_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ def _line_to_offset(self, line: Union[int, str]) -> int:
if isinstance(line, str):
_line: Union[int, None]
if not (_line := self._name_map.get(line)):
raise ValueError("unknown line name: {}".format(line))
raise ValueError(f"unknown line name: {line}")
else:
return _line
else:
if not self._offset_map.get(line):
raise ValueError("unrequested line offset: {}".format(line))
raise ValueError(f"unrequested line offset: {line}")
return line

def get_values(
Expand Down Expand Up @@ -231,7 +231,7 @@ def __str__(self) -> str:
if not self._req:
return "<LineRequest RELEASED>"

return '<LineRequest chip="{}" num_lines={} offsets={} fd={}>'.format(
return '<LineRequest chip="{}" num_lines={} offsets={} fd={}>'.format( # noqa: UP032
self.chip_name, self.num_lines, self.offsets, self.fd
)

Expand Down
4 changes: 2 additions & 2 deletions bindings/python/gpiod/line_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class LineSettings:
# __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={}, edge_detection={}, bias={}, drive={}, active_low={}, debounce_period={}, event_clock={}, output_value={})".format(
return "gpiod.LineSettings(direction={}, edge_detection={}, bias={}, drive={}, active_low={}, debounce_period={}, event_clock={}, output_value={})".format( # noqa: UP032
str(self.direction),
str(self.edge_detection),
str(self.bias),
Expand All @@ -40,7 +40,7 @@ def __repr__(self) -> str:
)

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,
Expand Down

0 comments on commit 2f2381d

Please sign in to comment.