bindings: python: improve LineSettings.__repr__()
PATCH 1/1 bindings: python: improve LineSettings.__repr__()
From: Bartosz Golaszewski <[email protected]>
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 <[email protected]>
Signed-off-by Bartosz Golaszewski <[email protected]>
--- bindings/python/gpiod/line_settings.py | 2 +- bindings/python/tests/tests_line_settings.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
bindings/python/gpiod/line_settings.py +1 -1
@@ -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),
bindings/python/tests/tests_line_settings.py +1 -1
@@ -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))
Signature · 1 line
2.43.0
Bartosz Golaszewski
AppliedFrom: Bartosz Golaszewski <[email protected]>
Quoted 6 lines · Bartosz Golaszewski
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 isimport gpiod.
Applied, thanks!
[1/1] bindings: python: improve LineSettings.__repr__()
commit: f6c8c3321d8f30979fa593a4f6546ff3dccd2549
Best regards,
Signature · 1 line
Bartosz Golaszewski <[email protected]>