Fix type annotations in crates_updater.py.
* NamedTemporaryFile isn't a type (it's actually a function that
returns a "private" type
https://stackoverflow.com/a/64429225/632035)
* Fix tuple type syntax
* mypy can't infer that the tuple comprehension will have length 3, so
just be explicit.
Bug: None
Test: mypy .
Change-Id: If7bc6ec03cc9266b13da6b05908d7c1d4871ddce
diff --git a/crates_updater.py b/crates_updater.py
index ee476b5..497c228 100644
--- a/crates_updater.py
+++ b/crates_updater.py
@@ -21,6 +21,7 @@
import shutil
import tempfile
import urllib.request
+from typing import IO
import archive_utils
from base_updater import Updater
@@ -51,7 +52,7 @@
download_url: str
package: str
package_dir: str
- temp_file: tempfile.NamedTemporaryFile
+ temp_file: IO
def is_supported_url(self) -> bool:
if self._old_url.type != metadata_pb2.URL.HOMEPAGE:
@@ -62,10 +63,14 @@
self.package = match.group(1)
return True
- def _get_version_numbers(self, version: str) -> (int, int, int):
+ def _get_version_numbers(self, version: str) -> tuple[int, int, int]:
match = VERSION_MATCHER.match(version)
if match is not None:
- return tuple(int(match.group(i)) for i in range(1, 4))
+ return (
+ int(match.group(1)),
+ int(match.group(2)),
+ int(match.group(3)),
+ )
return (0, 0, 0)
def _is_newer_version(self, prev_version: str, prev_id: int,