From e20cd6adb006694024503cc668763774d6724f83 Mon Sep 17 00:00:00 2001 From: Benjamin Sparks Date: Wed, 27 May 2026 23:22:57 +0200 Subject: [PATCH] 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 https://github.com/python/typeshed/commit/bcb6399e155cb6444150fe98dfd9c24eb0343016. 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. --- nixos/lib/test-driver/src/test_driver/machine/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/nixos/lib/test-driver/src/test_driver/machine/__init__.py b/nixos/lib/test-driver/src/test_driver/machine/__init__.py index 790da705cf4f..db96445af912 100644 --- a/nixos/lib/test-driver/src/test_driver/machine/__init__.py +++ b/nixos/lib/test-driver/src/test_driver/machine/__init__.py @@ -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)