mirror of
https://github.com/servo/servo.git
synced 2025-07-19 05:13:55 +01:00
Mach: introduce Pyrefly for Python type checking, starting with the wpt folder (#37953)
This is the first stage of adopting Pyrefly. It introduces the Python folder and focuses on fixing issues around it. Testing: *Describe how this pull request is tested or why it doesn't require tests* Fixes: *Link to an issue this pull requests fixes or remove this line if there is no issue* --------- Signed-off-by: Jerens Lensun <jerensslensun@gmail.com>
This commit is contained in:
parent
2366a8bf9e
commit
55fd7b862f
14 changed files with 303 additions and 154 deletions
|
@ -2,7 +2,10 @@
|
|||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
|
||||
from wptrunner.wptcommandline import TestRoot
|
||||
from typing import Mapping
|
||||
import argparse
|
||||
from argparse import ArgumentParser
|
||||
import os
|
||||
import sys
|
||||
import tempfile
|
||||
|
@ -10,7 +13,7 @@ from collections import defaultdict
|
|||
from six import iterkeys, iteritems
|
||||
|
||||
from . import SERVO_ROOT, WPT_PATH
|
||||
from mozlog.structured import commandline
|
||||
from mozlog import commandline
|
||||
|
||||
# This must happen after importing from "." since it adds WPT
|
||||
# tools to the Python system path.
|
||||
|
@ -20,7 +23,7 @@ from wptrunner.wptcommandline import get_test_paths, set_from_config
|
|||
from wptrunner import wptlogging
|
||||
|
||||
|
||||
def create_parser():
|
||||
def create_parser() -> ArgumentParser:
|
||||
p = argparse.ArgumentParser()
|
||||
p.add_argument(
|
||||
"--check-clean", action="store_true", help="Check that updating the manifest doesn't lead to any changes"
|
||||
|
@ -31,7 +34,7 @@ def create_parser():
|
|||
return p
|
||||
|
||||
|
||||
def update(check_clean=True, rebuild=False, logger=None, **kwargs):
|
||||
def update(check_clean=True, rebuild=False, logger=None, **kwargs) -> int:
|
||||
if not logger:
|
||||
logger = wptlogging.setup(kwargs, {"mach": sys.stdout})
|
||||
kwargs = {
|
||||
|
@ -52,7 +55,7 @@ def update(check_clean=True, rebuild=False, logger=None, **kwargs):
|
|||
return _update(logger, test_paths, rebuild)
|
||||
|
||||
|
||||
def _update(logger, test_paths, rebuild):
|
||||
def _update(logger, test_paths: Mapping[str, TestRoot], rebuild) -> int:
|
||||
for url_base, paths in iteritems(test_paths):
|
||||
manifest_path = os.path.join(paths.metadata_path, "MANIFEST.json")
|
||||
cache_subdir = os.path.relpath(os.path.dirname(manifest_path), os.path.dirname(__file__))
|
||||
|
@ -67,7 +70,7 @@ def _update(logger, test_paths, rebuild):
|
|||
return 0
|
||||
|
||||
|
||||
def _check_clean(logger, test_paths):
|
||||
def _check_clean(logger, test_paths: Mapping[str, TestRoot]) -> int:
|
||||
manifests_by_path = {}
|
||||
rv = 0
|
||||
for url_base, paths in iteritems(test_paths):
|
||||
|
@ -104,7 +107,7 @@ def _check_clean(logger, test_paths):
|
|||
return rv
|
||||
|
||||
|
||||
def diff_manifests(logger, manifest_path, old_manifest, new_manifest):
|
||||
def diff_manifests(logger, manifest_path, old_manifest, new_manifest) -> bool:
|
||||
"""Lint the differences between old and new versions of a
|
||||
manifest. Differences are considered significant (and so produce
|
||||
lint errors) if they produce a meaningful difference in the actual
|
||||
|
@ -167,5 +170,5 @@ def diff_manifests(logger, manifest_path, old_manifest, new_manifest):
|
|||
return clean
|
||||
|
||||
|
||||
def log_error(logger, manifest_path, msg):
|
||||
def log_error(logger, manifest_path, msg: str) -> None:
|
||||
logger.lint_error(path=manifest_path, message=msg, lineno=0, source="", linter="wpt-manifest")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue