From a7da03384509b3cd1c9294b1344cb320667eaf3c Mon Sep 17 00:00:00 2001 From: InsanePrawn Date: Fri, 18 Feb 2022 03:30:21 +0100 Subject: [PATCH] distro: fix type annotations to please mypy --- chroot/abstract.py | 4 ++-- distro/distro.py | 7 ++++--- distro/package.py | 6 +++++- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/chroot/abstract.py b/chroot/abstract.py index 2a093cd..a7c28ae 100644 --- a/chroot/abstract.py +++ b/chroot/abstract.py @@ -2,7 +2,7 @@ import atexit import logging import os import subprocess -from typing import Protocol +from typing import Protocol, Union from shlex import quote as shell_quote from config import config @@ -195,7 +195,7 @@ class Chroot(AbstractChroot): self.active = False def run_cmd(self, - script: str, + script: Union[str, list[str]], inner_env: dict[str, str] = {}, outer_env: dict[str, str] = os.environ.copy() | {'QEMU_LD_PREFIX': '/usr/aarch64-linux-gnu'}, attach_tty: bool = False, diff --git a/distro/distro.py b/distro/distro.py index 2d5bf62..41727d4 100644 --- a/distro/distro.py +++ b/distro/distro.py @@ -1,3 +1,5 @@ +from typing import Optional + from constants import ARCHES, BASE_DISTROS, REPOSITORIES, KUPFER_HTTPS, CHROOT_PATHS from generator import generate_pacman_conf_body from config import config @@ -57,8 +59,7 @@ def get_kupfer_https(arch: str) -> Distro: return get_kupfer(arch, KUPFER_HTTPS) -def get_kupfer_local(arch: str = None, in_chroot: bool = True) -> Distro: - if not arch: - arch = config.runtime['arch'] +def get_kupfer_local(arch: Optional[str] = None, in_chroot: bool = True) -> Distro: + arch = arch or config.runtime['arch'] dir = CHROOT_PATHS['packages'] if in_chroot else config.get_path('packages') return get_kupfer(arch, f"file://{dir}/$arch/$repo") diff --git a/distro/package.py b/distro/package.py index 537d79c..25e276f 100644 --- a/distro/package.py +++ b/distro/package.py @@ -1,8 +1,11 @@ +from typing import Optional + + class PackageInfo: name: str version: str filename: str - resolved_url: str + resolved_url: Optional[str] def __init__( self, @@ -19,6 +22,7 @@ class PackageInfo: def __repr__(self): return f'{self.name}@{self.version}' + @staticmethod def parse_desc(desc_str: str, resolved_url=None): """Parses a desc file, returning a PackageInfo"""