Re: [libgpiod][PATCH 11/22] bindings: python: cast return value of LineRequest.get_values

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Sep 27, 2024 at 8:57 PM Vincent Fazio <vfazio@xxxxxxxxxxx> wrote:
>
> The `values` argument of `_ext.Request.get_values` uses a preallocated
> `list[None]` as a buffer that is populated with `Value`s by the external
> module that are then returned from the function.
>
> Use `cast` to inform the type checker it's a `list[Value]` despite how
> it's allocated.
>
> Also, as `lines` is typed as an `Iterable`, there is no guarantee it has
> a `__len__` method. Instead, use the size of the `offsets` array to
> allocate the buffer.
>
> Signed-off-by: Vincent Fazio <vfazio@xxxxxxxxxxx>
> ---
>  bindings/python/gpiod/line_request.py | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/bindings/python/gpiod/line_request.py b/bindings/python/gpiod/line_request.py
> index a1ca64cfd82c32be5de3fc53f6c981026911bb9c..917020b9ec7046dd8e10158f70efb555fc87eade 100644
> --- a/bindings/python/gpiod/line_request.py
> +++ b/bindings/python/gpiod/line_request.py
> @@ -122,7 +122,7 @@ class LineRequest:
>
>          offsets = [self._line_to_offset(line) for line in lines]
>
> -        buf = [None] * len(lines)
> +        buf = cast(list[Value], [None] * len(offsets))
>
>          self._req.get_values(offsets, buf)
>          return buf
>
> --
> 2.34.1
>

I think this is the first time in this series where I understand what
cast() really does. Looks good.

Bart





[Index of Archives]     [Linux SPI]     [Linux Kernel]     [Linux ARM (vger)]     [Linux ARM MSM]     [Linux Omap]     [Linux Arm]     [Linux Tegra]     [Fedora ARM]     [Linux for Samsung SOC]     [eCos]     [Linux Fastboot]     [Gcc Help]     [Git]     [DCCP]     [IETF Announce]     [Security]     [Linux MIPS]     [Yosemite Campsites]

  Powered by Linux