From 9df9a98ae51979e130a1b847851dc416dfe79783 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Thu, 6 Feb 2025 02:45:43 +0300 Subject: [PATCH 1/4] gh-129707: Check `Tools/build/compute-changes.py` with `mypy` --- Tools/build/compute-changes.py | 8 ++------ Tools/build/mypy.ini | 2 +- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/Tools/build/compute-changes.py b/Tools/build/compute-changes.py index 105ba58cc9d941..cdff7225e5b57d 100644 --- a/Tools/build/compute-changes.py +++ b/Tools/build/compute-changes.py @@ -14,10 +14,6 @@ from dataclasses import dataclass from pathlib import Path -TYPE_CHECKING = False -if TYPE_CHECKING: - from collections.abc import Set - GITHUB_DEFAULT_BRANCH = os.environ["GITHUB_DEFAULT_BRANCH"] GITHUB_CODEOWNERS_PATH = Path(".github/CODEOWNERS") GITHUB_WORKFLOWS_PATH = Path(".github/workflows") @@ -83,7 +79,7 @@ def git_branches() -> tuple[str, str]: def get_changed_files( ref_a: str = GITHUB_DEFAULT_BRANCH, ref_b: str = "HEAD" -) -> Set[Path]: +) -> frozenset[Path]: """List the files changed between two Git refs, filtered by change type.""" args = ("git", "diff", "--name-only", f"{ref_a}...{ref_b}", "--") print(*args) @@ -94,7 +90,7 @@ def get_changed_files( return frozenset(map(Path, filter(None, map(str.strip, changed_files)))) -def process_changed_files(changed_files: Set[Path]) -> Outputs: +def process_changed_files(changed_files: frozenset[Path]) -> Outputs: run_tests = False run_ci_fuzz = False run_docs = False diff --git a/Tools/build/mypy.ini b/Tools/build/mypy.ini index 0e5d6e874a72e5..d04e81b7592504 100644 --- a/Tools/build/mypy.ini +++ b/Tools/build/mypy.ini @@ -1,5 +1,5 @@ [mypy] -files = Tools/build/generate_sbom.py +files = Tools/build/generate_sbom.py, Tools/build/compute-changes.py pretty = True # Make sure Python can still be built From cad043062a7b4fd018c9beb022415ea2b703e508 Mon Sep 17 00:00:00 2001 From: sobolevn Date: Thu, 6 Feb 2025 12:01:29 +0300 Subject: [PATCH 2/4] Address review --- Tools/build/compute-changes.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Tools/build/compute-changes.py b/Tools/build/compute-changes.py index cdff7225e5b57d..8dd62c4d56ae8c 100644 --- a/Tools/build/compute-changes.py +++ b/Tools/build/compute-changes.py @@ -14,6 +14,10 @@ from dataclasses import dataclass from pathlib import Path +TYPE_CHECKING = False +if False: + from collections.abc import Set # type: ignore[unreachable] + GITHUB_DEFAULT_BRANCH = os.environ["GITHUB_DEFAULT_BRANCH"] GITHUB_CODEOWNERS_PATH = Path(".github/CODEOWNERS") GITHUB_WORKFLOWS_PATH = Path(".github/workflows") @@ -79,7 +83,7 @@ def git_branches() -> tuple[str, str]: def get_changed_files( ref_a: str = GITHUB_DEFAULT_BRANCH, ref_b: str = "HEAD" -) -> frozenset[Path]: +) -> Set[Path]: """List the files changed between two Git refs, filtered by change type.""" args = ("git", "diff", "--name-only", f"{ref_a}...{ref_b}", "--") print(*args) @@ -90,7 +94,7 @@ def get_changed_files( return frozenset(map(Path, filter(None, map(str.strip, changed_files)))) -def process_changed_files(changed_files: frozenset[Path]) -> Outputs: +def process_changed_files(changed_files: Set[Path]) -> Outputs: run_tests = False run_ci_fuzz = False run_docs = False From 5f70e8e1b29319bb2b51be811c0730ce927c082f Mon Sep 17 00:00:00 2001 From: sobolevn Date: Thu, 6 Feb 2025 12:03:45 +0300 Subject: [PATCH 3/4] Address review --- Tools/build/compute-changes.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tools/build/compute-changes.py b/Tools/build/compute-changes.py index 8dd62c4d56ae8c..105ba58cc9d941 100644 --- a/Tools/build/compute-changes.py +++ b/Tools/build/compute-changes.py @@ -15,8 +15,8 @@ from pathlib import Path TYPE_CHECKING = False -if False: - from collections.abc import Set # type: ignore[unreachable] +if TYPE_CHECKING: + from collections.abc import Set GITHUB_DEFAULT_BRANCH = os.environ["GITHUB_DEFAULT_BRANCH"] GITHUB_CODEOWNERS_PATH = Path(".github/CODEOWNERS") From c51334be0bd3b713fabb403ce9774841dbeb516f Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Date: Thu, 6 Feb 2025 11:26:35 +0000 Subject: [PATCH 4/4] Try multi-line files Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> --- Tools/build/mypy.ini | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Tools/build/mypy.ini b/Tools/build/mypy.ini index d04e81b7592504..06224163884a98 100644 --- a/Tools/build/mypy.ini +++ b/Tools/build/mypy.ini @@ -1,5 +1,7 @@ [mypy] -files = Tools/build/generate_sbom.py, Tools/build/compute-changes.py +files = + Tools/build/compute-changes.py, + Tools/build/generate_sbom.py pretty = True # Make sure Python can still be built