From 73ed6cb1a8d20792a78e107085396719408d2b9d Mon Sep 17 00:00:00 2001 From: Thomas Sibley Date: Thu, 5 Sep 2024 13:18:16 -0700 Subject: [PATCH] runner.conda: Ignore newly failing type check for tarfile.open() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This started failing recently with newer typeshed stubs for tarfile.open() (and/or newer stubs for requests.Response?). mypy fails with: nextstrain/cli/runner/conda.py:220: error: Argument "fileobj" to "open" has incompatible type "Union[HTTPResponse, Any]"; expected "Optional[IO[bytes]]" and pyright with: nextstrain/cli/runner/conda.py:220:14 - error: No overloads for "open" match the provided arguments (reportCallIssue) nextstrain/cli/runner/conda.py:220:58 - error: Argument of type "Literal['r|*']" cannot be assigned to parameter "mode" of type "_FileCreationModes" in function "open"   Type "Literal['r|*']" is not assignable to type "_FileCreationModes"     "Literal['r|*']" is not assignable to type "Literal['a']"     "Literal['r|*']" is not assignable to type "Literal['w']"     "Literal['r|*']" is not assignable to type "Literal['x']" (reportArgumentType) I'm guessing the difference is because they match the different overloads of tarfile.open(). I dug into it a little¹, but the stubs here seem a bit scattershot at the moment so I stopped and went with an ignore. An alternative fix is casting response.raw to BinaryIO, but that seemed uglier and worse than an ignore. ¹ See (implicated) and (open, may fix?) and (open, may fix?) --- nextstrain/cli/runner/conda.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nextstrain/cli/runner/conda.py b/nextstrain/cli/runner/conda.py index a850dfd0..e938c7c2 100644 --- a/nextstrain/cli/runner/conda.py +++ b/nextstrain/cli/runner/conda.py @@ -217,7 +217,7 @@ def setup_micromamba(dry_run: bool = False, force: bool = False) -> bool: assert content_type == "application/x-tar", \ f"unknown content-type for micromamba dist: {content_type}" - with tarfile.open(fileobj = response.raw, mode = "r|*") as tar: + with tarfile.open(fileobj = response.raw, mode = "r|*") as tar: # type: ignore # Ignore archive members starting with "/" and or including ".." parts, # as these can be used (maliciously or accidentally) to overwrite # unintended files (e.g. files outside of MICROMAMBA_ROOT).