All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kent Gibson <warthog618@gmail.com>
To: linux-gpio@vger.kernel.org, brgl@bgdev.pl
Cc: Kent Gibson <warthog618@gmail.com>
Subject: [libgpiod][PATCH 2/2] bindings: python: support casting line.Value to bool
Date: Wed, 22 May 2024 08:46:43 +0800	[thread overview]
Message-ID: <20240522004643.96863-3-warthog618@gmail.com> (raw)
In-Reply-To: <20240522004643.96863-1-warthog618@gmail.com>

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@gmail.com>
---
 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


  parent reply	other threads:[~2024-05-22  0:47 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-22  0:46 [libgpiod][PATCH 0/2] support casting line.Value to bool Kent Gibson
2024-05-22  0:46 ` [libgpiod][PATCH 1/2] bindings: python: tests: add test for " Kent Gibson
2024-05-22  0:46 ` Kent Gibson [this message]
2024-05-22 16:22 ` [libgpiod][PATCH 0/2] support " brgl
2024-05-22 23:57   ` Kent Gibson
2024-05-23  0:32     ` Kent Gibson
2024-05-23  7:50       ` Bartosz Golaszewski
2024-05-23  7:55 ` Bartosz Golaszewski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240522004643.96863-3-warthog618@gmail.com \
    --to=warthog618@gmail.com \
    --cc=brgl@bgdev.pl \
    --cc=linux-gpio@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.