NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.74k stars 13.86k forks source link

mypy update broke the python test infrastructure #83458

Closed samueldr closed 4 years ago

samueldr commented 4 years ago

As noted in #83074, the goal post got moved, we have new errors to deal with.

/nix/store/zdqc0fsmcx3ihgjmykf2pdd98wmn79np-test-driver.py:118: error:(B Item (B"None"(B of (B"Optional[IO[bytes]]"(B has no attribute (B"readline"(B(B
/nix/store/zdqc0fsmcx3ihgjmykf2pdd98wmn79np-test-driver.py:143: error:(B Argument 1 to (B"XMLGenerator"(B has incompatible type (B"BinaryIO"(B; expected (B"Union[TextIOBase, RawIOBase, StreamWriter, StreamReaderWriter, _Writable, None]"(B(B
/nix/store/zdqc0fsmcx3ihgjmykf2pdd98wmn79np-test-driver.py:742: error:(B Item (B"None"(B of (B"Optional[IO[bytes]]"(B has no attribute (B"__iter__"(B (not iterable)(B
Found 3 errors in 1 file (checked 1 source file)(B

I am not working on fixing this, I am not a python developer.

cc @flokli @tfc who recently worked on the testing infra. Don't hesitate to ping other likely saviors.

samueldr commented 4 years ago

We may want to add a proper warning for each of the three linters, in their respective files, to properly test the test infra with the PR, fixing new issues as they come.

tfc commented 4 years ago

cc @Mic92 as you did most of the mypy support additions.

i just did this to fix 2 of 3 errors but the BinaryIO type mismatch in the XMLGenerator constructor looks like a riddle to me. The type checker also does static analysis and wants to see that these type can't be None, so that was easy to fix.

diff --git a/nixos/lib/test-driver/test-driver.py b/nixos/lib/test-driver/test-driver.py
index c27947bc610..2c93ff2e9bd 100644
--- a/nixos/lib/test-driver/test-driver.py
+++ b/nixos/lib/test-driver/test-driver.py
@@ -115,6 +115,7 @@ def create_vlan(vlan_nr: str) -> Tuple[str, str, "subprocess.Popen[bytes]", Any]
     fd.write("version\n")
     # TODO: perl version checks if this can be read from
     # an if not, dies. we could hang here forever. Fix it.
+    assert vde_process.stdout is not None
     vde_process.stdout.readline()
     if not os.path.exists(os.path.join(vde_socket, "ctl")):
         raise Exception("cannot start vde_switch")
@@ -739,6 +740,7 @@ class Machine:
         self.shell, _ = self.shell_socket.accept()

         def process_serial_output() -> None:
+            assert self.process.stdout is not None
             for _line in self.process.stdout:
                 # Ignore undecodable bytes that may occur in boot menus
                 line = _line.decode(errors="ignore").replace("\r", "").rstrip()
tfc commented 4 years ago

oh, @Emantor was faster. Awesome, thank you!