nixos-test-driver: adher to select's interface

TL;DR add `assert` to correct location for type-narrowing

typeshed recently updated their definition of `select` in bcb6399e15.
The result is that the members of the lists passed to `select` now
require an upper bound of `FileDescriptorLike`.

The `self.shell` variable is typed as `socket | None`, but previously
passed checking against typeshed due to the missing upper-bound.
Despite the source code including a type-narrowing `assert`, `ty` does
not make use of it within the inner function that `select` is used in,
meaning `self.shell` wasn't narrowed at the appropriate place.
Now that typeshed has added this upper-bound, type-checking starts to fail, as evidenced in
https://github.com/NixOS/nixpkgs/pull/523288#issuecomment-4529738483.

So the correct fix is just to add the `assert` into the inner function.
This commit is contained in:
Benjamin Sparks
2026-05-27 23:22:57 +02:00
parent f23bab4666
commit e20cd6adb0

View File

@@ -1031,6 +1031,7 @@ class QemuMachine(BaseMachine):
As soon as we read some data from the socket here, we assume that
our root shell is operational.
"""
assert self.shell
(ready, _, _) = select.select([self.shell], [], [], timeout_secs)
return bool(ready)