From 1ffac7db4cf255ad805e697fc4aefd10a07eed69 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Wed, 13 Aug 2025 00:34:53 +0300 Subject: [PATCH 1/3] gh-133403: Run `mypy` on `Tools/build/check_warnings.py` --- .github/workflows/mypy.yml | 1 + Tools/build/check_warnings.py | 32 +++++++++++++++++++++++--------- Tools/build/mypy.ini | 1 + 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/.github/workflows/mypy.yml b/.github/workflows/mypy.yml index 0413d5f905d771..753345d91e877f 100644 --- a/.github/workflows/mypy.yml +++ b/.github/workflows/mypy.yml @@ -15,6 +15,7 @@ on: - "Misc/mypy/**" - "Tools/build/mypy.ini" - "Tools/build/check_extension_modules.py" + - "Tools/build/check_warnings.py" - "Tools/build/compute-changes.py" - "Tools/build/deepfreeze.py" - "Tools/build/generate_sbom.py" diff --git a/Tools/build/check_warnings.py b/Tools/build/check_warnings.py index 3f49d8e7f2ee48..b7fee1cd475ece 100644 --- a/Tools/build/check_warnings.py +++ b/Tools/build/check_warnings.py @@ -8,21 +8,29 @@ import sys from collections import defaultdict from pathlib import Path -from typing import NamedTuple +from typing import NamedTuple, TypedDict class IgnoreRule(NamedTuple): file_path: str - count: int + count: int # type: ignore[assignment] ignore_all: bool = False is_directory: bool = False +class CompileWarning(TypedDict): + file: str + line: str + column: str + message: str + option: str + + def parse_warning_ignore_file(file_path: str) -> set[IgnoreRule]: """ Parses the warning ignore file and returns a set of IgnoreRules """ - files_with_expected_warnings = set() + files_with_expected_warnings: set[IgnoreRule] = set() with Path(file_path).open(encoding="UTF-8") as ignore_rules_file: files_with_expected_warnings = set() for i, line in enumerate(ignore_rules_file): @@ -46,7 +54,7 @@ def parse_warning_ignore_file(file_path: str) -> set[IgnoreRule]: ) sys.exit(1) if ignore_all: - count = 0 + count = '0' files_with_expected_warnings.add( IgnoreRule( @@ -61,7 +69,7 @@ def extract_warnings_from_compiler_output( compiler_output: str, compiler_output_type: str, path_prefix: str = "", -) -> list[dict]: +) -> list[CompileWarning]: """ Extracts warnings from the compiler output based on compiler output type. Removes path prefix from file paths if provided. @@ -78,8 +86,12 @@ def extract_warnings_from_compiler_output( r"(?P.*):(?P\d+):(?P\d+): warning: " r"(?P.*) (?P