mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-29 07:06:55 +08:00
Bump flake8-pyi to 24.4.1 (#11791)
This commit is contained in:
10
.github/workflows/tests.yml
vendored
10
.github/workflows/tests.yml
vendored
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
Reference in New Issue
Block a user