From: Vincent Fazio <vfazio@gmail.com>
To: linux-gpio@vger.kernel.org
Cc: Vincent Fazio <vfazio@gmail.com>
Subject: [libgpiod][PATCH] bindings: python: allow closing Chip multiple times
Date: Thu, 2 Apr 2026 18:03:14 -0500 [thread overview]
Message-ID: <20260402230315.6501-1-vfazio@gmail.com> (raw)
Allow closing a Chip mulitple times without throwing a ChipClosedError
to adhere to common Python semantics.
Signed-off-by: Vincent Fazio <vfazio@gmail.com>
---
bindings/python/gpiod/chip.py | 6 +++---
bindings/python/tests/tests_chip.py | 8 --------
2 files changed, 3 insertions(+), 11 deletions(-)
diff --git a/bindings/python/gpiod/chip.py b/bindings/python/gpiod/chip.py
index 8113fa9..6b7b32b 100644
--- a/bindings/python/gpiod/chip.py
+++ b/bindings/python/gpiod/chip.py
@@ -99,9 +99,9 @@ class Chip:
Close the associated GPIO chip descriptor. The chip object must no
longer be used after this method is called.
"""
- self._check_closed()
- cast("_ext.Chip", self._chip).close()
- self._chip = None
+ if self._chip is not None:
+ self._chip.close()
+ self._chip = None
def get_info(self) -> ChipInfo:
"""
diff --git a/bindings/python/tests/tests_chip.py b/bindings/python/tests/tests_chip.py
index d5a64b3..9007885 100644
--- a/bindings/python/tests/tests_chip.py
+++ b/bindings/python/tests/tests_chip.py
@@ -184,14 +184,6 @@ class ClosedChipCannotBeUsed(TestCase):
with chip:
_ = chip.fd
- def test_close_chip_twice(self) -> None:
- sim = gpiosim.Chip(label="foobar")
- chip = gpiod.Chip(sim.dev_path)
- chip.close()
-
- with self.assertRaises(gpiod.ChipClosedError):
- chip.close()
-
class StringRepresentation(TestCase):
def setUp(self) -> None:
--
2.43.0
next reply other threads:[~2026-04-02 23:03 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-02 23:03 Vincent Fazio [this message]
2026-04-03 9:05 ` [libgpiod][PATCH] bindings: python: allow closing Chip multiple times Bartosz Golaszewski
2026-04-03 13:09 ` Vincent Fazio
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=20260402230315.6501-1-vfazio@gmail.com \
--to=vfazio@gmail.com \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox