mirror of
https://github.com/servo/servo.git
synced 2025-07-18 21:03:45 +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
|
@ -13,7 +13,7 @@ import urllib.error
|
|||
import urllib.parse
|
||||
import urllib.request
|
||||
|
||||
from typing import List, NamedTuple, Optional, Union
|
||||
from typing import List, NamedTuple, Optional, Union, cast, Callable
|
||||
|
||||
import mozlog
|
||||
import mozlog.formatters
|
||||
|
@ -31,12 +31,12 @@ TRACKER_DASHBOARD_SECRET_ENV_VAR = "INTERMITTENT_TRACKER_DASHBOARD_SECRET_PROD"
|
|||
TRACKER_DASHBOARD_MAXIMUM_OUTPUT_LENGTH = 1024
|
||||
|
||||
|
||||
def set_if_none(args: dict, key: str, value):
|
||||
def set_if_none(args: dict, key: str, value: bool | int | str) -> None:
|
||||
if key not in args or args[key] is None:
|
||||
args[key] = value
|
||||
|
||||
|
||||
def run_tests(default_binary_path: str, **kwargs):
|
||||
def run_tests(default_binary_path: str, **kwargs) -> int:
|
||||
print(f"Running WPT tests with {default_binary_path}")
|
||||
|
||||
# By default, Rayon selects the number of worker threads based on the
|
||||
|
@ -99,7 +99,7 @@ def run_tests(default_binary_path: str, **kwargs):
|
|||
wptcommandline.check_args(kwargs)
|
||||
|
||||
mozlog.commandline.log_formatters["servo"] = (
|
||||
ServoFormatter,
|
||||
cast(Callable, ServoFormatter),
|
||||
"Servo's grouping output formatter",
|
||||
)
|
||||
|
||||
|
@ -147,7 +147,7 @@ class GithubContextInformation(NamedTuple):
|
|||
|
||||
|
||||
class TrackerDashboardFilter:
|
||||
def __init__(self):
|
||||
def __init__(self) -> None:
|
||||
base_url = os.environ.get(TRACKER_API_ENV_VAR, TRACKER_API)
|
||||
self.headers = {"Content-Type": "application/json"}
|
||||
if TRACKER_DASHBOARD_SECRET_ENV_VAR in os.environ and os.environ[TRACKER_DASHBOARD_SECRET_ENV_VAR]:
|
||||
|
@ -202,7 +202,7 @@ class TrackerDashboardFilter:
|
|||
data["subtest"] = result.subtest
|
||||
return data
|
||||
|
||||
def report_failures(self, unexpected_results: List[UnexpectedResult]):
|
||||
def report_failures(self, unexpected_results: List[UnexpectedResult]) -> None:
|
||||
attempts = []
|
||||
for result in unexpected_results:
|
||||
attempts.append(self.make_data_from_result(result))
|
||||
|
@ -244,12 +244,12 @@ def filter_intermittents(unexpected_results: List[UnexpectedResult], output_path
|
|||
print(f"Filtering {len(unexpected_results)} unexpected results for known intermittents via <{dashboard.url}>")
|
||||
dashboard.report_failures(unexpected_results)
|
||||
|
||||
def add_result(output, text, results: List[UnexpectedResult], filter_func) -> None:
|
||||
def add_result(output: list[str], text: str, results: List[UnexpectedResult], filter_func) -> None:
|
||||
filtered = [str(result) for result in filter(filter_func, results)]
|
||||
if filtered:
|
||||
output += [f"{text} ({len(filtered)}): ", *filtered]
|
||||
|
||||
def is_stable_and_unexpected(result):
|
||||
def is_stable_and_unexpected(result: UnexpectedResult) -> bool:
|
||||
return not result.flaky and not result.issues
|
||||
|
||||
output: List[str] = []
|
||||
|
@ -271,7 +271,7 @@ def filter_intermittents(unexpected_results: List[UnexpectedResult], output_path
|
|||
|
||||
def write_unexpected_only_raw_log(
|
||||
unexpected_results: List[UnexpectedResult], raw_log_file: str, filtered_raw_log_file: str
|
||||
):
|
||||
) -> None:
|
||||
tests = [result.path for result in unexpected_results]
|
||||
print(f"Writing unexpected-only raw log to {filtered_raw_log_file}")
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue