diff mbox series

[libgpiod,13/22] bindings: python: selectively use f-strings

Message ID 20240927-vfazio-mypy-v1-13-91a7c2e20884@xes-inc.com
State New
Headers show
Series bindings: python: conform to mypy and ruff linter recommendations | expand

Commit Message

Vincent Fazio Sept. 27, 2024, 6:53 p.m. UTC
Dataclasses are not migrated to f-strings so readability isn't impacted.

Signed-off-by: Vincent Fazio <vfazio@xes-inc.com>
---
 bindings/python/gpiod/chip.py          | 8 +++-----
 bindings/python/gpiod/chip_info.py     | 2 +-
 bindings/python/gpiod/edge_event.py    | 2 +-
 bindings/python/gpiod/info_event.py    | 2 +-
 bindings/python/gpiod/line_info.py     | 2 +-
 bindings/python/gpiod/line_request.py  | 2 +-
 bindings/python/gpiod/line_settings.py | 4 ++--
 7 files changed, 10 insertions(+), 12 deletions(-)

Comments

Bartosz Golaszewski Oct. 8, 2024, 1:24 p.m. UTC | #1
On Fri, Sep 27, 2024 at 8:57 PM Vincent Fazio <vfazio@xes-inc.com> wrote:
>
> Dataclasses are not migrated to f-strings so readability isn't impacted.

Could you add some details on what f-strings are and why they're preferred?

>
>      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

I guess the comment tells the analyzers to ignore this? Maybe mention
that too in the commit message?

Bart
diff mbox series

Patch

diff --git a/bindings/python/gpiod/chip.py b/bindings/python/gpiod/chip.py
index 27785d63806619ff70e7c75f7dd102894d3a4ec1..e2a82203501160cf63d86a7c8c3e2d92469e2fb9 100644
--- a/bindings/python/gpiod/chip.py
+++ b/bindings/python/gpiod/chip.py
@@ -281,9 +281,7 @@  class Chip:
         ).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
@@ -350,7 +348,7 @@  class Chip:
         if not self._chip:
             return "<Chip CLOSED>"
 
-        return 'gpiod.Chip("{}")'.format(self.path)
+        return f'gpiod.Chip("{self.path}")'
 
     def __str__(self) -> str:
         """
@@ -359,7 +357,7 @@  class Chip:
         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()
         )
 
diff --git a/bindings/python/gpiod/chip_info.py b/bindings/python/gpiod/chip_info.py
index eb585d6d7efa26492163dc0a731ba263d0232099..27c28131ad4f883f3712e4201a0c325274f5fefc 100644
--- a/bindings/python/gpiod/chip_info.py
+++ b/bindings/python/gpiod/chip_info.py
@@ -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
         )
diff --git a/bindings/python/gpiod/edge_event.py b/bindings/python/gpiod/edge_event.py
index 0d401d896a79dc5204e7ea86f202e37acbd24758..7f5cd4d345785ceb549e2888629898818a4ab293 100644
--- a/bindings/python/gpiod/edge_event.py
+++ b/bindings/python/gpiod/edge_event.py
@@ -40,7 +40,7 @@  class EdgeEvent:
         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,
diff --git a/bindings/python/gpiod/info_event.py b/bindings/python/gpiod/info_event.py
index d9e9564e21338cd8d1e28c567fa2ed2ac29ceb00..ed531f2c3ab36e3c146c87bfdbabd3f95ab8b643 100644
--- a/bindings/python/gpiod/info_event.py
+++ b/bindings/python/gpiod/info_event.py
@@ -31,6 +31,6 @@  class InfoEvent:
         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
         )
diff --git a/bindings/python/gpiod/line_info.py b/bindings/python/gpiod/line_info.py
index 5ea9568fd5c963c77f53c56ef748ac1e80872ed9..1aca142387992d2d836fb2b5672f0b45249691af 100644
--- a/bindings/python/gpiod/line_info.py
+++ b/bindings/python/gpiod/line_info.py
@@ -59,7 +59,7 @@  class LineInfo:
         )
 
     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,
diff --git a/bindings/python/gpiod/line_request.py b/bindings/python/gpiod/line_request.py
index a9b5105e5cc5bc5f857300ba3e0eb7528ed6ae80..dcb711095a39002be650aaaf6f158807c37f27e1 100644
--- a/bindings/python/gpiod/line_request.py
+++ b/bindings/python/gpiod/line_request.py
@@ -232,7 +232,7 @@  class LineRequest:
         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
         )
 
diff --git a/bindings/python/gpiod/line_settings.py b/bindings/python/gpiod/line_settings.py
index 6c6518dbc958423393790a39d69e94802eda8547..2aca71c9c5cd02d1add663f5d430dcf0153706b9 100644
--- a/bindings/python/gpiod/line_settings.py
+++ b/bindings/python/gpiod/line_settings.py
@@ -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=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),
@@ -40,7 +40,7 @@  class LineSettings:
         )
 
     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,