From e7dfac345cc8f4416d54c3735ed7ce956147de70 Mon Sep 17 00:00:00 2001 From: ShaharNaveh <50263213+ShaharNaveh@users.noreply.github.com> Date: Sat, 14 Feb 2026 10:07:45 +0200 Subject: [PATCH 1/4] Basic script to detect leftover patches --- scripts/check_leftover_patches.py | 52 +++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 scripts/check_leftover_patches.py diff --git a/scripts/check_leftover_patches.py b/scripts/check_leftover_patches.py new file mode 100644 index 00000000000..af4bf08c715 --- /dev/null +++ b/scripts/check_leftover_patches.py @@ -0,0 +1,52 @@ +#!/usr/bin/env python +import ast +import pathlib +import sys + +ROOT = pathlib.Path(__file__).parents[1] +TEST_DIR = ROOT / "Lib" / "test" + + +def main(): + exit_status = 0 + for file in TEST_DIR.rglob("**/*.py"): + try: + contents = file.read_text(encoding="utf-8") + except UnicodeDecodeError: + continue + + try: + tree = ast.parse(contents) + except SyntaxError: + pass + + for node in ast.walk(tree): + if not isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)): + continue + + name = node.name + if not name.startswith("test"): + continue + + if node.decorator_list: + continue + + func_code = ast.unparse(node.body) + if func_code in ( + f"await super().{name}()", + f"return await super().{name}()", + f"return super().{name}()", + f"super().{name}()", + ): + exit_status += 1 + rel = file.relative_to(ROOT) + lineno = node.lineno + print( + f"{rel}:{name}:{lineno} is a test patch that can be safely removed", + file=sys.stderr, + ) + return exit_status + + +if __name__ == "__main__": + exit(main()) From f0e5abb73f90b46d3e16ae0f408b08af596630f2 Mon Sep 17 00:00:00 2001 From: ShaharNaveh <50263213+ShaharNaveh@users.noreply.github.com> Date: Sat, 14 Feb 2026 10:12:54 +0200 Subject: [PATCH 2/4] Add CI step --- .github/workflows/ci.yaml | 9 ++++++++- ...ck_leftover_patches.py => check_redundant_patches.py} | 0 2 files changed, 8 insertions(+), 1 deletion(-) rename scripts/{check_leftover_patches.py => check_redundant_patches.py} (100%) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 4e272da4c42..29d8811a6b8 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -456,9 +456,16 @@ jobs: run: python -I scripts/whats_left.py --no-default-features --features "$(sed -e 's/--[^ ]*//g' <<< "${{ env.CARGO_ARGS }}" | tr -d '[:space:]'),threading" # no jit on macOS for now lint: - name: Check Rust code with clippy + name: Lint Rust & Python code runs-on: ubuntu-latest steps: + - uses: actions/setup-python@v6.2.0 + with: + python-version: ${{ env.PYTHON_VERSION }} + + - name: Check for redundant test patches + run: python scripts/check_redundant_patches.py + - uses: actions/checkout@v6.0.2 - uses: dtolnay/rust-toolchain@stable with: diff --git a/scripts/check_leftover_patches.py b/scripts/check_redundant_patches.py similarity index 100% rename from scripts/check_leftover_patches.py rename to scripts/check_redundant_patches.py From 7bdefc52c0345b1c03927b50fda2512d83b86ea5 Mon Sep 17 00:00:00 2001 From: ShaharNaveh <50263213+ShaharNaveh@users.noreply.github.com> Date: Sat, 14 Feb 2026 10:15:48 +0200 Subject: [PATCH 3/4] Checkout code --- .github/workflows/ci.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 29d8811a6b8..2d549491674 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -459,6 +459,7 @@ jobs: name: Lint Rust & Python code runs-on: ubuntu-latest steps: + - uses: actions/checkout@v6.0.2 - uses: actions/setup-python@v6.2.0 with: python-version: ${{ env.PYTHON_VERSION }} From 0da173a88437440b39a8759b71dfd1d1d1f9284a Mon Sep 17 00:00:00 2001 From: ShaharNaveh <50263213+ShaharNaveh@users.noreply.github.com> Date: Sun, 15 Feb 2026 10:56:36 +0200 Subject: [PATCH 4/4] coderabbit review --- .github/workflows/ci.yaml | 1 - scripts/check_redundant_patches.py | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 2d549491674..7f0f7b8af2d 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -467,7 +467,6 @@ jobs: - name: Check for redundant test patches run: python scripts/check_redundant_patches.py - - uses: actions/checkout@v6.0.2 - uses: dtolnay/rust-toolchain@stable with: components: clippy diff --git a/scripts/check_redundant_patches.py b/scripts/check_redundant_patches.py index af4bf08c715..25cd2e1229e 100644 --- a/scripts/check_redundant_patches.py +++ b/scripts/check_redundant_patches.py @@ -18,7 +18,7 @@ def main(): try: tree = ast.parse(contents) except SyntaxError: - pass + continue for node in ast.walk(tree): if not isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)):