diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 1a96d5a14892..59393429306b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -34,16 +34,6 @@ jobs: - run: uv pip install -r requirements-tests.txt --system - run: python ./tests/check_typeshed_structure.py - new-syntax: - name: Ensure new syntax usage - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: actions/setup-python@v5 - with: - python-version: "3.12" - - run: ./tests/check_new_syntax.py - pytype: name: Run pytype against the stubs runs-on: ubuntu-latest diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ba361da9d1ac..5dbeac0d84c6 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -37,7 +37,7 @@ repos: - id: flake8 additional_dependencies: - "flake8-noqa==1.4.0" # must match requirements-tests.txt - - "flake8-pyi==24.4.0" # must match requirements-tests.txt + - "flake8-pyi==24.4.1" # must match requirements-tests.txt types: [file] types_or: [python, pyi] - repo: meta diff --git a/requirements-tests.txt b/requirements-tests.txt index eb9698f2ccf4..eaaa1f42ca6d 100644 --- a/requirements-tests.txt +++ b/requirements-tests.txt @@ -4,7 +4,7 @@ black==24.3.0 # must match .pre-commit-config.yaml flake8==7.0.0 # must match .pre-commit-config.yaml flake8-noqa==1.4.0 # must match .pre-commit-config.yaml -flake8-pyi==24.4.0 # must match .pre-commit-config.yaml +flake8-pyi==24.4.1 # must match .pre-commit-config.yaml mypy==1.9.0 pre-commit-hooks==4.5.0 # must match .pre-commit-config.yaml pyright==1.1.358 diff --git a/scripts/runtests.py b/scripts/runtests.py index 219886aca867..7a17c299f01f 100755 --- a/scripts/runtests.py +++ b/scripts/runtests.py @@ -86,8 +86,6 @@ def main() -> None: print("\nRunning check_typeshed_structure.py...") check_structure_result = subprocess.run([sys.executable, "tests/check_typeshed_structure.py"]) - print("\nRunning check_new_syntax.py...") - check_new_syntax_result = subprocess.run([sys.executable, "tests/check_new_syntax.py"]) strict_params = _get_strict_params(path) print(f"\nRunning Pyright ({'stricter' if strict_params else 'base' } configs) for Python {python_version}...") @@ -180,7 +178,6 @@ def main() -> None: [ pre_commit_result.returncode, check_structure_result.returncode, - check_new_syntax_result.returncode, pyright_returncode, mypy_result.returncode, getattr(stubtest_result, "returncode", 0), @@ -207,7 +204,6 @@ def main() -> None: that the autofixes did sensible things.""" ) print("Check structure:", _SUCCESS if check_structure_result.returncode == 0 else _FAILED) - print("Check new syntax:", _SUCCESS if check_new_syntax_result.returncode == 0 else _FAILED) if pyright_skipped: print("Pyright:", _SKIPPED) else: diff --git a/tests/README.md b/tests/README.md index ae48d19bcb0c..9826e9a58790 100644 --- a/tests/README.md +++ b/tests/README.md @@ -9,8 +9,6 @@ tests the stubs with [mypy](https://github.com/python/mypy/) stubs, guarding against accidental regressions. - `tests/check_typeshed_structure.py` checks that typeshed's directory structure and metadata files are correct. -- `tests/check_new_syntax.py` contains linter-like checks to ensure -that certain code conventions are followed. - `tests/stubtest_stdlib.py` checks standard library stubs against the objects at runtime. - `tests/stubtest_third_party.py` checks third-party stubs against the diff --git a/tests/check_new_syntax.py b/tests/check_new_syntax.py deleted file mode 100755 index 830d1f2e5e2f..000000000000 --- a/tests/check_new_syntax.py +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/bin/env python3 - -from __future__ import annotations - -import ast -import sys -from itertools import chain -from pathlib import Path - - -def check_new_syntax(tree: ast.AST, path: Path, stub: str) -> list[str]: - errors: list[str] = [] - - class IfFinder(ast.NodeVisitor): - def visit_If(self, node: ast.If) -> None: - if ( - isinstance(node.test, ast.Compare) - and ast.unparse(node.test).startswith("sys.version_info < ") - and node.orelse - and not (len(node.orelse) == 1 and isinstance(node.orelse[0], ast.If)) # elif statement (#6728) - ): - new_syntax = "if " + ast.unparse(node.test).replace("<", ">=", 1) - errors.append( - f"{path}:{node.lineno}: When using if/else with sys.version_info, " - f"put the code for new Python versions first, e.g. `{new_syntax}`" - ) - self.generic_visit(node) - - IfFinder().visit(tree) - return errors - - -def main() -> None: - errors: list[str] = [] - for path in chain(Path("stdlib").rglob("*.pyi"), Path("stubs").rglob("*.pyi")): - with open(path, encoding="UTF-8") as f: - stub = f.read() - tree = ast.parse(stub) - errors.extend(check_new_syntax(tree, path, stub)) - - if errors: - print("\n".join(errors)) - sys.exit(1) - - -if __name__ == "__main__": - assert sys.version_info >= (3, 9), "Python 3.9+ is required to run this test" - main()