Bump flake8-pyi to 24.4.1 (#11791)

This commit is contained in:
Alex Waygood
2024-04-19 18:07:56 +01:00
committed by GitHub
parent ade9412f85
commit 57f3dcac8d
6 changed files with 2 additions and 66 deletions

View File

@@ -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

View File

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