mach: Enable ANN rules (type annotations) for ruff Python linter (#38531)

This changes will introduce [flake8-annotations
(ANN)](https://docs.astral.sh/ruff/rules/#flake8-annotations-ann) for
python type annotation, this will make all thing related to function
strictly typed in python

This rule will start to affected this directory from now:
- /python -> Root directory
- /python/tidy
- /python/wpt

Testing: `./mach test-tidy`
Fixes: Not related to any issues

---------

Signed-off-by: Jerens Lensun <jerensslensun@gmail.com>
This commit is contained in:
Jerens Lensun 2025-08-14 18:36:17 +08:00 committed by GitHub
parent 9c1ee4be83
commit 797db25c4e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 122 additions and 70 deletions

View file

@ -3,6 +3,7 @@
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
# pylint: disable=missing-docstring
from typing import Any
import os
import subprocess
import shutil
@ -21,7 +22,7 @@ TEST_ROOT = os.path.join(WPT_PATH, "tests")
META_ROOTS = [os.path.join(WPT_PATH, "meta"), os.path.join(WPT_PATH, "meta-legacy")]
def do_sync(**kwargs) -> int:
def do_sync(**kwargs: str) -> int:
last_commit = subprocess.check_output(["git", "log", "-1"])
# Commits should always be authored by the GitHub Actions bot.
@ -94,7 +95,7 @@ def remove_unused_metadata() -> None:
shutil.rmtree(directory)
def update_tests(**kwargs) -> int:
def update_tests(**kwargs: Any) -> int:
def set_if_none(args: dict, key: str, value: str) -> None:
if key not in args or args[key] is None:
args[key] = value
@ -113,11 +114,11 @@ def update_tests(**kwargs) -> int:
return 0 if run_update(**kwargs) else 1
def run_update(**kwargs) -> bool:
def run_update(**kwargs: Any) -> bool:
"""Run the update process returning True if the process is successful."""
logger = setup_logging(kwargs, {"mach": sys.stdout})
return WPTUpdate(logger, **kwargs).run() != exit_unclean
def create_parser(**_kwargs) -> ArgumentParser:
def create_parser(**_kwargs: Any) -> ArgumentParser:
return wptcommandline.create_parser_update()