Skip to content

Commit

Permalink
repogen: clean up some Python type hint stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
throwaway96 committed Mar 28, 2024
1 parent 8cc58ed commit d7ca08a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions repogen/ipk_file.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import io
import json
import tarfile
from typing import TypedDict, NotRequired, Optional
from typing import TypedDict, NotRequired

import ar
from debian_parser import PackagesParser


class Control(TypedDict):
version: str
installedSize: Optional[int]
installedSize: int | None


class AppInfo(TypedDict):
Expand All @@ -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())
Expand Down
8 changes: 4 additions & 4 deletions repogen/pkg_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions repogen/pkg_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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']]
Expand Down
4 changes: 2 additions & 2 deletions repogen/pkg_registery.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d7ca08a

Please sign in to comment.