bindings: python: allow closing Chip multiple times
PATCH 1/1 bindings: python: allow closing Chip multiple times
Allow closing a Chip mulitple times without throwing a ChipClosedError to adhere to common Python semantics.
Signed-off-by Vincent Fazio <[email protected]>
--- bindings/python/gpiod/chip.py | 6 +++--- bindings/python/tests/tests_chip.py | 8 -------- 2 files changed, 3 insertions(+), 11 deletions(-)
bindings/python/gpiod/chip.py +3 -3
@@ -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: """
bindings/python/tests/tests_chip.py +0 -8
@@ -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:
Signature · 1 line
2.43.0
Bartosz Golaszewski
maintainerQuoted 6 lines · Vincent Fazio
Allow closing a Chip mulitple times without throwing a ChipClosedError to adhere to common Python semantics.
Signed-off-by Vincent Fazio <[email protected]>---
Would you mind just elaborating on what these common semantics are in the commit message for python noobs like myself? :)
Bartosz
Quoted 3 lines · Bartosz Golaszewski
Would you mind just elaborating on what these common semantics are in the commit message for python noobs like myself? :)
Will do