From d7ca08ab66b68db72a53d36f7355fac467407464 Mon Sep 17 00:00:00 2001 From: throwaway96 <68320646+throwaway96@users.noreply.github.com> Date: Thu, 28 Mar 2024 16:48:09 -0400 Subject: [PATCH] repogen: clean up some Python type hint stuff --- repogen/ipk_file.py | 6 +++--- repogen/pkg_info.py | 8 ++++---- repogen/pkg_manifest.py | 4 ++-- repogen/pkg_registery.py | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/repogen/ipk_file.py b/repogen/ipk_file.py index 4db4d12..f475eab 100644 --- a/repogen/ipk_file.py +++ b/repogen/ipk_file.py @@ -1,7 +1,7 @@ import io import json import tarfile -from typing import TypedDict, NotRequired, Optional +from typing import TypedDict, NotRequired import ar from debian_parser import PackagesParser @@ -9,7 +9,7 @@ class Control(TypedDict): version: str - installedSize: Optional[int] + installedSize: int | None class AppInfo(TypedDict): @@ -20,7 +20,7 @@ class AppInfo(TypedDict): appDescription: NotRequired[str] -def get_appinfo(ipk_path: str) -> (Control, AppInfo): +def get_appinfo(ipk_path: str) -> tuple[Control, AppInfo]: with open(ipk_path, 'rb') as f: archive = ar.Archive(f) control_file = io.BytesIO(archive.open('control.tar.gz', mode='rb').read()) diff --git a/repogen/pkg_info.py b/repogen/pkg_info.py index dab2b14..fc0f353 100644 --- a/repogen/pkg_info.py +++ b/repogen/pkg_info.py @@ -2,7 +2,7 @@ import sys from datetime import datetime from pathlib import Path -from typing import TypedDict, Optional, List, NotRequired +from typing import TypedDict, List, NotRequired import nh3 @@ -46,7 +46,7 @@ def load_registry(info_path: Path) -> tuple[str, PackageRegistry]: return pkgid, content -def from_package_info_file(info_path: Path, offline=False) -> Optional[PackageInfo]: +def from_package_info_file(info_path: Path, offline=False) -> PackageInfo | None: pkgid, content = load_registry(info_path) return from_package_info(pkgid, content, offline) @@ -104,10 +104,10 @@ def from_package_info(pkgid: str, content: PackageRegistry, offline=False) -> Pa return pkginfo -def list_packages(pkgdir: Path, packages: Optional[List[str]] = None, offline: bool = False) -> List[PackageInfo]: +def list_packages(pkgdir: Path, packages: List[str] | None = None, offline: bool = False) -> List[PackageInfo]: paths: List[Path] = [f for f in pkgdir.iterdir() if f.is_file()] - def map_package_info(p: Path) -> Optional[PackageInfo]: + def map_package_info(p: Path) -> PackageInfo | None: pkgid, content = load_registry(p) if packages and pkgid not in packages: return None diff --git a/repogen/pkg_manifest.py b/repogen/pkg_manifest.py index bbbf951..475d435 100644 --- a/repogen/pkg_manifest.py +++ b/repogen/pkg_manifest.py @@ -3,7 +3,7 @@ import urllib.parse from datetime import datetime from email.utils import parsedate_to_datetime -from typing import TypedDict, Optional, NotRequired, Literal +from typing import TypedDict, NotRequired, Literal from urllib.parse import urljoin from urllib.request import url2pathname @@ -22,7 +22,7 @@ class PackageManifest(TypedDict): title: str version: str type: str - appDescription: Optional[str] + appDescription: str | None iconUri: str sourceUrl: NotRequired[str] rootRequired: NotRequired[bool | Literal['optional']] diff --git a/repogen/pkg_registery.py b/repogen/pkg_registery.py index 75b6301..5359a44 100644 --- a/repogen/pkg_registery.py +++ b/repogen/pkg_registery.py @@ -22,14 +22,14 @@ class PackageRegistry(TypedDict): funding: NotRequired[dict[str, List[str]]] -def parse_yml_package(p: Path) -> (str, PackageRegistry): +def parse_yml_package(p: Path) -> tuple[str, PackageRegistry]: with p.open(encoding='utf-8') as f: content: PackageRegistry = yaml.safe_load(f) return p.stem, content # noinspection PyUnresolvedReferences -def load_py_package(p: Path) -> (str, PackageRegistry): +def load_py_package(p: Path) -> tuple[str, PackageRegistry]: pkgid = p.stem spec = importlib.util.spec_from_file_location(f"pkg.{pkgid}", p) module = importlib.util.module_from_spec(spec)