Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -456,10 +456,17 @@ 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/[email protected]
- uses: actions/[email protected]
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Check for redundant test patches
run: python scripts/check_redundant_patches.py

- uses: dtolnay/rust-toolchain@stable
with:
components: clippy
Expand Down
52 changes: 52 additions & 0 deletions scripts/check_redundant_patches.py
Original file line number Diff line number Diff line change
@@ -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:
continue

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())
Loading