Message ID | 20240927-vfazio-mypy-v1-11-91a7c2e20884@xes-inc.com |
---|---|
State | New |
Headers | show |
Series | [libgpiod,01/22] bindings: python: clean up imports and exports | expand |
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
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@xes-inc.com> --- bindings/python/gpiod/line_request.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)