public inbox for linux-gpio@vger.kernel.org
 help / color / mirror / Atom feed
* [libgpiod][PATCH] bindings: python: allow closing Chip multiple times
@ 2026-04-02 23:03 Vincent Fazio
  2026-04-03  9:05 ` Bartosz Golaszewski
  0 siblings, 1 reply; 3+ messages in thread
From: Vincent Fazio @ 2026-04-02 23:03 UTC (permalink / raw)
  To: linux-gpio; +Cc: Vincent Fazio

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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [libgpiod][PATCH] bindings: python: allow closing Chip multiple times
  2026-04-02 23:03 [libgpiod][PATCH] bindings: python: allow closing Chip multiple times Vincent Fazio
@ 2026-04-03  9:05 ` Bartosz Golaszewski
  2026-04-03 13:09   ` Vincent Fazio
  0 siblings, 1 reply; 3+ messages in thread
From: Bartosz Golaszewski @ 2026-04-03  9:05 UTC (permalink / raw)
  To: Vincent Fazio; +Cc: linux-gpio

On Fri, Apr 3, 2026 at 1:03 AM Vincent Fazio <vfazio@gmail.com> wrote:
>
> Allow closing a Chip mulitple times without throwing a ChipClosedError
> to adhere to common Python semantics.
>
> Signed-off-by: Vincent Fazio <vfazio@gmail.com>
> ---

Would you mind just elaborating on what these common semantics are in
the commit message for python noobs like myself? :)

Bartosz

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [libgpiod][PATCH] bindings: python: allow closing Chip multiple times
  2026-04-03  9:05 ` Bartosz Golaszewski
@ 2026-04-03 13:09   ` Vincent Fazio
  0 siblings, 0 replies; 3+ messages in thread
From: Vincent Fazio @ 2026-04-03 13:09 UTC (permalink / raw)
  To: Bartosz Golaszewski; +Cc: linux-gpio

On Fri, Apr 3, 2026 at 4:06 AM Bartosz Golaszewski <brgl@kernel.org> wrote:
>
> Would you mind just elaborating on what these common semantics are in
> the commit message for python noobs like myself? :)

Will do

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-04-03 13:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-02 23:03 [libgpiod][PATCH] bindings: python: allow closing Chip multiple times Vincent Fazio
2026-04-03  9:05 ` Bartosz Golaszewski
2026-04-03 13:09   ` Vincent Fazio

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox