diff --git a/src/fuzzfetch/args.py b/src/fuzzfetch/args.py index 0208385..43c7962 100644 --- a/src/fuzzfetch/args.py +++ b/src/fuzzfetch/args.py @@ -3,13 +3,14 @@ # You can obtain one at http://mozilla.org/MPL/2.0/. """Fuzzfetch argument parser""" +from __future__ import annotations + import itertools import platform as std_platform from argparse import ArgumentParser, Namespace from collections.abc import Sequence from logging import getLogger from pathlib import Path -from typing import Optional from .models import BuildSearchOrder, Platform from .utils import extract_branch_from_ns, is_namespace @@ -187,7 +188,7 @@ def sanity_check(self, args: Namespace) -> None: if "js" not in args.target and args.sim: self.parser.error("Simulator builds are only available for JS targets") - def parse_args(self, argv: Optional[Sequence[str]] = None) -> Namespace: + def parse_args(self, argv: Sequence[str] | None = None) -> Namespace: """Parse and validate args Arguments: diff --git a/src/fuzzfetch/core.py b/src/fuzzfetch/core.py index 34b1516..ce451b6 100644 --- a/src/fuzzfetch/core.py +++ b/src/fuzzfetch/core.py @@ -3,6 +3,8 @@ # You can obtain one at http://mozilla.org/MPL/2.0/. """Core fuzzfetch implementation""" +from __future__ import annotations + import configparser import logging import os @@ -14,7 +16,7 @@ from datetime import datetime, timedelta from importlib.metadata import PackageNotFoundError, version from pathlib import Path -from typing import Any, Optional, Union +from typing import Any from pytz import timezone @@ -47,12 +49,12 @@ class Fetcher: def __init__( self, branch: str, - build: Union[str, BuildTask], - flags: Union[Sequence[bool], BuildFlags], + build: str | BuildTask, + flags: Sequence[bool] | BuildFlags, targets: Sequence[str], - platform: Optional[Platform] = None, - simulated: Optional[str] = None, - nearest: Optional[BuildSearchOrder] = None, + platform: Platform | None = None, + simulated: str | None = None, + nearest: BuildSearchOrder | None = None, ) -> None: """ Arguments: @@ -276,7 +278,7 @@ def changeset(self) -> str: return self.build_info["moz_source_stamp"] @property - def moz_info(self) -> dict[str, Union[str, bool, int]]: + def moz_info(self) -> dict[str, str | bool | int]: """Return the build's mozinfo""" if "moz_info" not in self._memo: try: @@ -661,9 +663,9 @@ def extract_dmg(self, path: PathArg = ".") -> None: @classmethod def from_args( cls, - argv: Optional[Sequence[str]] = None, + argv: Sequence[str] | None = None, skip_dir_check: bool = False, - ) -> tuple["Fetcher", dict[str, Union[bool, Path, Sequence[str]]]]: + ) -> tuple[Fetcher, dict[str, bool | Path | Sequence[str]]]: """Construct a Fetcher from given command line arguments. Arguments: diff --git a/src/fuzzfetch/download.py b/src/fuzzfetch/download.py index cb21021..b6b8141 100644 --- a/src/fuzzfetch/download.py +++ b/src/fuzzfetch/download.py @@ -3,9 +3,10 @@ # You can obtain one at http://mozilla.org/MPL/2.0/. """Fuzzfetch download utils""" +from __future__ import annotations + import time from logging import getLogger -from typing import Optional, Union from requests import Response, Session from requests.exceptions import RequestException @@ -17,7 +18,7 @@ LOG = getLogger("fuzzfetch") -def iec(number: Union[float, int]) -> str: +def iec(number: float | int) -> str: """Format a number using IEC multi-byte prefixes. Arguments: @@ -33,7 +34,7 @@ def iec(number: Union[float, int]) -> str: return f"{number:0.2f}{prefixes[0]}" -def si(number: Union[float, int]) -> str: # pylint: disable=invalid-name +def si(number: float | int) -> str: # pylint: disable=invalid-name """Format a number using SI prefixes. Arguments: @@ -49,7 +50,7 @@ def si(number: Union[float, int]) -> str: # pylint: disable=invalid-name return f"{number:0.2f}{prefixes[0]}" -def get_url(url: str, timeout: Optional[float] = None) -> Response: +def get_url(url: str, timeout: float | None = None) -> Response: """Retrieve requested URL""" try: data = HTTP_SESSION.get(url, stream=True, timeout=timeout) @@ -60,7 +61,7 @@ def get_url(url: str, timeout: Optional[float] = None) -> Response: return data -def resolve_url(url: str, timeout: Optional[float] = None) -> Response: +def resolve_url(url: str, timeout: float | None = None) -> Response: """Resolve requested URL""" try: data = HTTP_SESSION.head(url, timeout=timeout) @@ -71,7 +72,7 @@ def resolve_url(url: str, timeout: Optional[float] = None) -> Response: return data -def download_url(url: str, outfile: PathArg, timeout: Optional[float] = 30.0) -> None: +def download_url(url: str, outfile: PathArg, timeout: float | None = 30.0) -> None: """Download a URL to a local path. Arguments: diff --git a/src/fuzzfetch/models.py b/src/fuzzfetch/models.py index 4660656..caed002 100644 --- a/src/fuzzfetch/models.py +++ b/src/fuzzfetch/models.py @@ -3,6 +3,8 @@ # You can obtain one at http://mozilla.org/MPL/2.0/. """Fuzzfetch internal models""" +from __future__ import annotations + import itertools import platform as std_platform from collections.abc import Iterable, Iterator @@ -10,7 +12,7 @@ from datetime import datetime from enum import Enum from logging import getLogger -from typing import Any, Optional +from typing import Any from pytz import timezone from requests import RequestException @@ -106,11 +108,11 @@ class BuildTask: def __init__( self, - build: Optional[str], - branch: Optional[str], - flags: Optional[BuildFlags], - platform: Optional["Platform"] = None, - simulated: Optional[str] = None, + build: str | None, + branch: str | None, + flags: BuildFlags | None, + platform: Platform | None = None, + simulated: str | None = None, _blank: bool = False, ) -> None: """Retrieve the task JSON object @@ -119,8 +121,8 @@ def __init__( platform """ if _blank: - self.url: Optional[str] = None - self.queue_server: Optional[str] = None + self.url: str | None = None + self.queue_server: str | None = None self._data: dict[str, Any] = {} return assert build is not None @@ -156,9 +158,9 @@ def iterall( build: str, branch: str, flags: BuildFlags, - platform: Optional["Platform"] = None, - simulated: Optional[str] = None, - ) -> Iterator["BuildTask"]: + platform: Platform | None = None, + simulated: str | None = None, + ) -> Iterator[BuildTask]: """Generator for all possible BuildTasks with these parameters""" # Prepare build type if platform is None: @@ -201,7 +203,7 @@ def generate_task_paths( namespaces_: list[str], prod_: str, suffix_: str, - simulated_: Optional[str], + simulated_: str | None, ) -> Iterator[str]: for namespace in namespaces_: if simulated_ is not None: @@ -381,8 +383,8 @@ class Platform: def __init__( self, - system: Optional[str] = None, - machine: Optional[str] = None, + system: str | None = None, + machine: str | None = None, ) -> None: if system is None: system = std_platform.system() @@ -398,7 +400,7 @@ def __init__( self.gecko_platform = self.SUPPORTED[system][fixed_machine] @classmethod - def from_platform_guess(cls, build_string: str) -> "Platform": + def from_platform_guess(cls, build_string: str) -> Platform: """Create a platform object from a namespace build string""" match: list[str] = [] for system, platform in cls.SUPPORTED.items():