Skip to content

Commit

Permalink
Update typing format
Browse files Browse the repository at this point in the history
  • Loading branch information
jschwartzentruber committed Dec 20, 2024
1 parent dab2451 commit df361de
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 32 deletions.
5 changes: 3 additions & 2 deletions src/fuzzfetch/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
20 changes: 11 additions & 9 deletions src/fuzzfetch/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
13 changes: 7 additions & 6 deletions src/fuzzfetch/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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:
Expand Down
32 changes: 17 additions & 15 deletions src/fuzzfetch/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
# 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
from dataclasses import dataclass, fields
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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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()
Expand All @@ -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():
Expand Down

0 comments on commit df361de

Please sign in to comment.