diff mbox series

[libgpiod] bindings: python: improve LineSettings.__repr__()

Message ID 20240920143203.6377-1-brgl@bgdev.pl
State New
Headers show
Series [libgpiod] bindings: python: improve LineSettings.__repr__() | expand

Commit Message

Bartosz Golaszewski Sept. 20, 2024, 2:32 p.m. UTC
From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

Currently, for the output of LineSettings.__repr__() to be eval()able,
the user must have pulled all the relevant definitions from gpiod.line
within the scope where it is used. Modify the output so that all the user
needs is `import gpiod`.

Reported-by: Vincent Fazio <vfazio@gmail.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
 bindings/python/gpiod/line_settings.py       | 2 +-
 bindings/python/tests/tests_line_settings.py | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

Comments

Bartosz Golaszewski Sept. 27, 2024, 8:12 a.m. UTC | #1
From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>


On Fri, 20 Sep 2024 16:32:03 +0200, Bartosz Golaszewski wrote:
> Currently, for the output of LineSettings.__repr__() to be eval()able,
> the user must have pulled all the relevant definitions from gpiod.line
> within the scope where it is used. Modify the output so that all the user
> needs is `import gpiod`.
> 
> 

Applied, thanks!

[1/1] bindings: python: improve LineSettings.__repr__()
      commit: f6c8c3321d8f30979fa593a4f6546ff3dccd2549

Best regards,
diff mbox series

Patch

diff --git a/bindings/python/gpiod/line_settings.py b/bindings/python/gpiod/line_settings.py
index 41712cc..5e32194 100644
--- a/bindings/python/gpiod/line_settings.py
+++ b/bindings/python/gpiod/line_settings.py
@@ -27,7 +27,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):
-        return "gpiod.LineSettings(direction={}, edge_detection={}, bias={}, drive={}, active_low={}, debounce_period={}, event_clock={}, output_value={})".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(
             str(self.direction),
             str(self.edge_detection),
             str(self.bias),
diff --git a/bindings/python/tests/tests_line_settings.py b/bindings/python/tests/tests_line_settings.py
index c6ca720..83be3d9 100644
--- a/bindings/python/tests/tests_line_settings.py
+++ b/bindings/python/tests/tests_line_settings.py
@@ -69,7 +69,7 @@  class LineSettingsStringRepresentation(TestCase):
     def test_repr(self):
         self.assertEqual(
             repr(self.settings),
-            "gpiod.LineSettings(direction=Direction.OUTPUT, edge_detection=Edge.NONE, bias=Bias.AS_IS, drive=Drive.OPEN_SOURCE, active_low=True, debounce_period=datetime.timedelta(0), event_clock=Clock.MONOTONIC, output_value=Value.INACTIVE)",
+            "gpiod.LineSettings(direction=gpiod.line.Direction.OUTPUT, edge_detection=gpiod.line.Edge.NONE, bias=gpiod.line.Bias.AS_IS, drive=gpiod.line.Drive.OPEN_SOURCE, active_low=True, debounce_period=datetime.timedelta(0), event_clock=gpiod.line.Clock.MONOTONIC, output_value=gpiod.line.Value.INACTIVE)",
         )
 
         cmp = eval(repr(self.settings))