diff mbox series

[libgpiod,03/22] bindings: python: fix annotation of variable length tuples

Message ID 20240927-vfazio-mypy-v1-3-91a7c2e20884@xes-inc.com
State New
Headers show
Series bindings: python: conform to mypy and ruff linter recommendations | expand

Commit Message

Vincent Fazio Sept. 27, 2024, 6:53 p.m. UTC
Both `Chip.request_lines` and `LineRequest.reconfigure_lines` accept a
config argument that is allowed to be either a variable length tuple
of int | str, a str, or an int.

Python documentation [0] points out that variable length tuples need a
trailing ellipsis in their annotation.

[0]: https://docs.python.org/3/library/typing.html#annotating-tuples
Signed-off-by: Vincent Fazio <vfazio@xes-inc.com>
---
 bindings/python/gpiod/chip.py         | 4 +++-
 bindings/python/gpiod/line_request.py | 5 ++++-
 2 files changed, 7 insertions(+), 2 deletions(-)

Comments

Bartosz Golaszewski Oct. 8, 2024, 1:02 p.m. UTC | #1
On Fri, Sep 27, 2024 at 9:05 PM Vincent Fazio <vfazio@xes-inc.com> wrote:
>
> Both `Chip.request_lines` and `LineRequest.reconfigure_lines` accept a
> config argument that is allowed to be either a variable length tuple
> of int | str, a str, or an int.
>
> Python documentation [0] points out that variable length tuples need a
> trailing ellipsis in their annotation.
>
> [0]: https://docs.python.org/3/library/typing.html#annotating-tuples
> Signed-off-by: Vincent Fazio <vfazio@xes-inc.com>
> ---

For my own reference: looks good.

Bart
diff mbox series

Patch

diff --git a/bindings/python/gpiod/chip.py b/bindings/python/gpiod/chip.py
index 1a1bba4d6dd9e840a60394f1b74903f6ad15a0f4..93556b6ea6aa35b9ad6dc0cb840c33cb95170048 100644
--- a/bindings/python/gpiod/chip.py
+++ b/bindings/python/gpiod/chip.py
@@ -222,7 +222,9 @@  class Chip:
 
     def request_lines(
         self,
-        config: dict[tuple[Union[int, str]], Optional[LineSettings]],
+        config: dict[
+            Union[tuple[Union[int, str], ...], int, str], Optional[LineSettings]
+        ],
         consumer: Optional[str] = None,
         event_buffer_size: Optional[int] = None,
         output_values: Optional[dict[Union[int, str], Value]] = None,
diff --git a/bindings/python/gpiod/line_request.py b/bindings/python/gpiod/line_request.py
index 154174872e488fa478b27f5e83d65e6040aca367..f4e3f06d984d751d842b3c0e77a8db2e0e9a7a60 100644
--- a/bindings/python/gpiod/line_request.py
+++ b/bindings/python/gpiod/line_request.py
@@ -144,7 +144,10 @@  class LineRequest:
         self._req.set_values(mapped)
 
     def reconfigure_lines(
-        self, config: dict[tuple[Union[int, str]], LineSettings]
+        self,
+        config: dict[
+            Union[tuple[Union[int, str], ...], int, str], Optional[LineSettings]
+        ],
     ) -> None:
         """
         Reconfigure requested lines.