bindings: python: tests: add type hints to internal members
authorVincent Fazio <vfazio@xes-inc.com>
Thu, 14 Nov 2024 14:51:13 +0000 (08:51 -0600)
committerBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Tue, 19 Nov 2024 14:23:58 +0000 (15:23 +0100)
commitf04f58ae1d548542134a31f48a1285b59a2915fc
treeb8bb7689320a99618a51e71b04d811c1d170b89a
parentd9313c18a06432ec10732b94885f915bdbc722bf
bindings: python: tests: add type hints to internal members

Add type hints for internal members of the test cases so type checkers
can ensure the code properly constrains to these types and accounts for
scenarios where the values are `None`.

In most cases, the type checker is allowed to assume the inferred type
upon assignment.

An example is any test case that creates a `Chip` as part of its `setUp`
method. Many of these tests subsequently set the reference to `None` in
`tearDown` to free up resources to be collected by the GC.

If the member was "properly" typed to be `Optional`, all references in
the unit tests would need to be guarded by an assert or a cast or
ignored by the type checker. This is noisy and doesn't add value since
for the life of the test it should always be a valid reference.

Instead, allow `tearDown` to violate the inferred type and inform the
type checker to ignore the assignment via directive.

If the tests are ever changed to set the member to something other than
the inferred type outside of `tearDown`, explicit type hints and proper
checks should be added.

Signed-off-by: Vincent Fazio <vfazio@xes-inc.com>
Link: https://lore.kernel.org/r/20241114145116.2123714-21-vfazio@xes-inc.com
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
bindings/python/tests/tests_chip.py
bindings/python/tests/tests_chip_info.py
bindings/python/tests/tests_edge_event.py
bindings/python/tests/tests_info_event.py
bindings/python/tests/tests_line_info.py