Re: [libgpiod][PATCH 09/22] bindings: python: fix LineRequest union-attr type errors

[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:
>
> Since `LineRequest._req` can be `None`, it's necessary to inform type
> checkers of the state of the object to silence the union-attr errors.
>
> Type checkers may not be able to infer that an object is not `None` from
> an earlier call (such as `_check_released`).
>
> Instead of littering the code with "# type: ignore" comments, use casts
> to inform type checkers that objects are not `None`.
>
> Using `assert` is another option, however this duplicates the logic in
> `_check_released` so is redundant at best and, at worst, is not a safe
> replacement as `assert` can be elided in optimized Python environments
> and these checks need to be runtime enforced.
>
> Also, convert singular ints or strs to a tuple instead of a list to keep
> with the inferred variable type of `lines`.
>
> Signed-off-by: Vincent Fazio <vfazio@xxxxxxxxxxx>
> ---

Basically the same questions as with Chip. Is this a common pattern in the wild?

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