Skip to contentSkip to conversation

bindings: python: allow releasing a LineRequest multiple times

PATCH Applied Vincent Fazio 2 participants 2 messages Apr 3 – Apr 7 GPIO

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 bindings: python: allow releasing a LineRequest multiple times

In Python, it is common for objects to allow their close method to be executed multiple times out of convenience. An example of this is the IOBase class [0] which is the base class of most file-like classes.

Update LineRequest.release to follow this example as it performs the same function as close.

[0]: https://docs.python.org/release/3.10.0/library/io.html#io.IOBase.close

---
 bindings/python/gpiod/line_request.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
bindings/python/gpiod/line_request.py +3 -3
index 0287791..a271080 100644
@@ -75,9 +75,9 @@ class LineRequest:
         Release this request and free all associated resources. The object must
         not be used after a call to this method.
         """
-        self._check_released()
-        cast("_ext.Request", self._req).release()
-        self._req = None
+        if self._req is not None:
+            self._req.release()
+            self._req = None
 
     def get_value(self, line: int | str) -> Value:
         """
Signature · 1 line
2.43.0
#1 lore raw
Quoted 8 lines · Vincent Fazio

In Python, it is common for objects to allow their close method to be executed multiple times out of convenience. An example of this is the IOBase class [0] which is the base class of most file-like classes.

Update LineRequest.release to follow this example as it performs the same function as close.

[...]

Applied, thanks!

[1/1] bindings: python: allow releasing a LineRequest multiple times

      https://git.kernel.org/brgl/c/bfffd6506ca11b409db7e478b6186256dfeb4d41

Best regards,

Signature · 1 line
Bartosz Golaszewski <[email protected]>