From: Daan De Meyer Date: Sun, 6 Aug 2023 12:25:52 +0000 (+0200) Subject: Always use str as the type parameter for CompletedProcess X-Git-Tag: v15~26^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=92ab68086c1777142a659f5322a02c851378edea;p=thirdparty%2Fmkosi.git Always use str as the type parameter for CompletedProcess We always set text=True when calling subprocess.run(), so we know that the type is going to be str, so let's encode that to get better type checking from mypy. --- diff --git a/mkosi/__init__.py b/mkosi/__init__.py index f847a5b36..979db913a 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -17,7 +17,7 @@ import uuid from collections.abc import Iterator, Sequence from pathlib import Path from textwrap import dedent -from typing import ContextManager, Optional, TextIO, Union, cast +from typing import ContextManager, Optional, TextIO, Union from mkosi.archive import extract_tar, make_cpio, make_tar from mkosi.config import ( @@ -397,7 +397,7 @@ def certificate_common_name(certificate: Path) -> str: if not sep: die("Missing '=' delimiter in openssl output") - return cast(str, value.strip()) + return value.strip() die(f"Certificate {certificate} is missing Common Name") diff --git a/mkosi/manifest.py b/mkosi/manifest.py index 81b2290ed..d81c5f098 100644 --- a/mkosi/manifest.py +++ b/mkosi/manifest.py @@ -137,8 +137,8 @@ class Manifest: if self.config.base_trees and installtime < self._init_timestamp: continue - package = PackageManifest("rpm", name, evr, arch, size) - self.packages.append(package) + manifest = PackageManifest("rpm", name, evr, arch, size) + self.packages.append(manifest) if not self.need_source_info(): continue @@ -157,7 +157,7 @@ class Manifest: source = SourcePackageManifest(srpm, changelog) self.source_packages[srpm] = source - source.add(package) + source.add(manifest) def record_deb_packages(self, root: Path) -> None: c = run(["dpkg-query", @@ -185,8 +185,8 @@ class Manifest: if self.config.base_trees and installtime < self._init_timestamp: continue - package = PackageManifest("deb", name, version, arch, size) - self.packages.append(package) + manifest = PackageManifest("deb", name, version, arch, size) + self.packages.append(manifest) if not self.need_source_info(): continue @@ -228,7 +228,7 @@ class Manifest: source_package = SourcePackageManifest(source, result.stdout.strip()) self.source_packages[source] = source_package - source_package.add(package) + source_package.add(manifest) def record_pkg_packages(self, root: Path) -> None: packages = sorted((root / "var/lib/pacman/local").glob("*/desc")) diff --git a/mkosi/tree.py b/mkosi/tree.py index 6c3266af0..3cd2173cf 100644 --- a/mkosi/tree.py +++ b/mkosi/tree.py @@ -4,7 +4,7 @@ import errno import shutil import subprocess from pathlib import Path -from typing import Optional, Sequence, cast +from typing import Optional, Sequence from mkosi.archive import extract_tar from mkosi.config import ConfigFeature, MkosiConfig @@ -15,8 +15,7 @@ from mkosi.util import umask def statfs(path: Path) -> str: - return cast(str, run(["stat", "--file-system", "--format", "%T", path], - stdout=subprocess.PIPE).stdout.strip()) + return run(["stat", "--file-system", "--format", "%T", path], stdout=subprocess.PIPE).stdout.strip() def is_subvolume(path: Path) -> bool: diff --git a/mkosi/types.py b/mkosi/types.py index 0648a0927..a2a3643b5 100644 --- a/mkosi/types.py +++ b/mkosi/types.py @@ -8,8 +8,8 @@ from typing import IO, TYPE_CHECKING, Any, Union # to a TypeError during compilation. # Let's be as strict as we can with the description for the usage we have. if TYPE_CHECKING: - CompletedProcess = subprocess.CompletedProcess[Any] - Popen = subprocess.Popen[Any] + CompletedProcess = subprocess.CompletedProcess[str] + Popen = subprocess.Popen[str] else: CompletedProcess = subprocess.CompletedProcess Popen = subprocess.Popen