[libgpiod][PATCH 2/2] bindings: python: support casting line.Value to bool

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Python types default to being truthy when cast to bool, so casting
line.Value to bool always returns True.

Add a line.Value.__bool__() operator to map the line value to bool as
one would intuitively expect, so ACTIVE is True and INACTIVE is False.

Signed-off-by: Kent Gibson <warthog618@xxxxxxxxx>
---
 bindings/python/gpiod/line.py | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/bindings/python/gpiod/line.py b/bindings/python/gpiod/line.py
index 1cc512f..d088fb4 100644
--- a/bindings/python/gpiod/line.py
+++ b/bindings/python/gpiod/line.py
@@ -14,6 +14,9 @@ class Value(Enum):
     INACTIVE = _ext.VALUE_INACTIVE
     ACTIVE = _ext.VALUE_ACTIVE
 
+    def __bool__(self):
+        return self == self.ACTIVE
+
 
 class Direction(Enum):
     """Direction settings."""
-- 
2.39.2





[Index of Archives]     [Linux SPI]     [Linux Kernel]     [Linux ARM (vger)]     [Linux ARM MSM]     [Linux Omap]     [Linux Arm]     [Linux Tegra]     [Fedora ARM]     [Linux for Samsung SOC]     [eCos]     [Linux Fastboot]     [Gcc Help]     [Git]     [DCCP]     [IETF Announce]     [Security]     [Linux MIPS]     [Yosemite Campsites]

  Powered by Linux